This commit is contained in:
Draycia committed 2020-09-25 01:45:35 -07:00
1 parent e263bccbfc
commit 8db4b9532c
63 files changed
+631 -471

No files matched your search

+9 -2
View File
@@ -1,3 +1,7 @@
plugins {
id 'java-library'
}
description 'CarbonChat-API' description 'CarbonChat-API'
dependencies { dependencies {
@@ -13,7 +17,10 @@ dependencies {
compile 'net.kyori:event-api:3.0.0' compile 'net.kyori:event-api:3.0.0'
compile 'net.kyori:registry:1.0.0-SNAPSHOT' compile 'net.kyori:registry:1.0.0-SNAPSHOT'
compile 'com.intellectualsites:cloud-core:1.0-SNAPSHOT' api 'com.intellectualsites:cloud-core:1.0-SNAPSHOT'
compileOnly 'org.spongepowered:configurate-yaml:4.0.0-SNAPSHOT' api 'org.spongepowered:configurate-yaml:4.0.0-SNAPSHOT'
api 'org.slf4j:slf4j-api:1.7.25'
api 'net.luckperms:api:5.1'
} }
@@ -5,9 +5,12 @@ import net.draycia.carbon.api.adventure.MessageProcessor;
import net.draycia.carbon.api.channels.ChannelRegistry; import net.draycia.carbon.api.channels.ChannelRegistry;
import net.draycia.carbon.api.commands.settings.CommandSettingsRegistry; import net.draycia.carbon.api.commands.settings.CommandSettingsRegistry;
import net.draycia.carbon.api.config.ModerationSettings; import net.draycia.carbon.api.config.ModerationSettings;
import net.draycia.carbon.api.messaging.MessageService;
import net.draycia.carbon.api.users.ChatUser;
import net.draycia.carbon.api.users.UserService; import net.draycia.carbon.api.users.UserService;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
import org.slf4j.Logger;
import java.nio.file.Path; import java.nio.file.Path;
@@ -23,12 +26,16 @@ public interface CarbonChat {
void reloadConfig(); void reloadConfig();
@NonNull Logger logger();
@NonNull Path dataFolder(); @NonNull Path dataFolder();
@NonNull UserService userService(); @NonNull <T extends ChatUser> UserService<T> userService();
@NonNull MessageProcessor messageProcessor(); @NonNull MessageProcessor messageProcessor();
@NonNull MessageService messageService();
@NonNull ChannelRegistry channelRegistry(); @NonNull ChannelRegistry channelRegistry();
@NonNull CommandSettingsRegistry commandSettingsRegistry(); @NonNull CommandSettingsRegistry commandSettingsRegistry();
@@ -6,10 +6,10 @@ import java.util.List;
public class Context { public class Context {
private @NonNull final String key; private final @NonNull String key;
private @NonNull final Object value; private final @NonNull Object value;
public Context(@NonNull final String key, @NonNull final Object value) { public Context(final @NonNull String key, final @NonNull Object value) {
this.key = key; this.key = key;
this.value = value; this.value = value;
} }
@@ -7,7 +7,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
public interface MessageProcessor { public interface MessageProcessor {
@NonNull Component processMessage(@Nullable final String input, @NonNull final String @NonNull ... placeholders); @NonNull Component processMessage(@Nullable final String input, final @NonNull String @NonNull ... placeholders);
@NonNull AudienceProvider audiences(); @NonNull AudienceProvider audiences();
@@ -18,7 +18,7 @@ public class ChannelRegistry implements Registry<String, ChatChannel> {
private ChatChannel defaultChannel = null; private ChatChannel defaultChannel = null;
@Override @Override
public @NonNull ChatChannel register(@NonNull final String key, @NonNull final ChatChannel value) { public @NonNull ChatChannel register(final @NonNull String key, final @NonNull ChatChannel value) {
this.registry.putIfAbsent(key, value); this.registry.putIfAbsent(key, value);
if (this.defaultChannel == null && value.isDefault()) { if (this.defaultChannel == null && value.isDefault()) {
@@ -29,16 +29,16 @@ public class ChannelRegistry implements Registry<String, ChatChannel> {
} }
@Override @Override
public @Nullable ChatChannel get(@NonNull final String key) { public @Nullable ChatChannel get(final @NonNull String key) {
return this.registry.get(key); return this.registry.get(key);
} }
public @Nullable ChatChannel channelOrDefault(@NonNull final String key) { public @Nullable ChatChannel channelOrDefault(final @NonNull String key) {
return this.registry.getOrDefault(key, this.defaultChannel()); return this.registry.getOrDefault(key, this.defaultChannel());
} }
@Override @Override
public @Nullable String key(@NonNull final ChatChannel value) { public @Nullable String key(final @NonNull ChatChannel value) {
return null; return null;
} }
@@ -5,6 +5,7 @@ import net.draycia.carbon.api.users.ChatUser;
import net.kyori.adventure.audience.ForwardingAudience; import net.kyori.adventure.audience.ForwardingAudience;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.TextColor; import net.kyori.adventure.text.format.TextColor;
import net.luckperms.api.model.group.Group;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
@@ -28,6 +29,13 @@ public interface ChatChannel extends ForwardingAudience {
*/ */
@Nullable TextColor channelColor(@NonNull ChatUser user); @Nullable TextColor channelColor(@NonNull ChatUser user);
/**
* Gets the string format for the specified group.
* @param group The group.
* @return The string format for the specified group.
*/
@Nullable String format(@NonNull Group group);
/** /**
* Gets the string format for the specified group. * Gets the string format for the specified group.
* @param group The group. * @param group The group.
@@ -35,6 +43,8 @@ public interface ChatChannel extends ForwardingAudience {
*/ */
@Nullable String format(@NonNull String group); @Nullable String format(@NonNull String group);
/** /**
* If this channel is the channel players get when they join for the first time. * If this channel is the channel players get when they join for the first time.
* Also the fallback channel in case the code is unable to find any given channel. * Also the fallback channel in case the code is unable to find any given channel.
@@ -14,12 +14,12 @@ public class CommandSettings {
private final boolean enabled; private final boolean enabled;
@Setting @Setting
private @NonNull final String name; private final @NonNull String name;
@Setting @Setting
private @NonNull final Set<@NonNull String> aliases; private final @NonNull Set<@NonNull String> aliases;
public CommandSettings(final boolean enabled, @NonNull final String name, @NonNull final Set<@NonNull String> aliases) { public CommandSettings(final boolean enabled, final @NonNull String name, final @NonNull Set<@NonNull String> aliases) {
this.enabled = enabled; this.enabled = enabled;
this.name = name; this.name = name;
this.aliases = aliases; this.aliases = aliases;
@@ -37,26 +37,26 @@ public class CommandSettingsRegistry implements Registry<String, CommandSettings
} }
@Setting @Setting
private @NonNull final Map<@NonNull String, @NonNull CommandSettings> registry = new HashMap<>(); private final @NonNull Map<@NonNull String, @NonNull CommandSettings> registry = new HashMap<>();
@Override @Override
public @NonNull CommandSettings register(@NonNull final String key, @NonNull final CommandSettings value) { public @NonNull CommandSettings register(final @NonNull String key, final @NonNull CommandSettings value) {
this.registry.put(key, value); this.registry.put(key, value);
return value; return value;
} }
@Override @Override
public @Nullable CommandSettings get(@NonNull final String key) { public @Nullable CommandSettings get(final @NonNull String key) {
return this.registry.get(key); return this.registry.get(key);
} }
public @Nullable CommandSettings get(@NonNull final ChatChannel channel) { public @Nullable CommandSettings get(final @NonNull ChatChannel channel) {
return this.get(channel.key()); return this.get(channel.key());
} }
@Override @Override
public @Nullable String key(@NonNull final CommandSettings value) { public @Nullable String key(final @NonNull CommandSettings value) {
return null; return null;
} }
@@ -14,12 +14,12 @@ public class ChannelRegisterEvent implements CarbonEvent {
@NonNull @NonNull
private final Registry<String, ChatChannel> registry; private final Registry<String, ChatChannel> registry;
public ChannelRegisterEvent(@NonNull final List<@NonNull ChatChannel> registeredChannels, @NonNull final Registry<String, ChatChannel> registry) { public ChannelRegisterEvent(final @NonNull List<@NonNull ChatChannel> registeredChannels, final @NonNull Registry<String, ChatChannel> registry) {
this.registeredChannels = registeredChannels; this.registeredChannels = registeredChannels;
this.registry = registry; this.registry = registry;
} }
public void register(@NonNull final ChatChannel chatChannel) { public void register(final @NonNull ChatChannel chatChannel) {
this.registry.register(chatChannel.key(), chatChannel); this.registry.register(chatChannel.key(), chatChannel);
} }
@@ -17,7 +17,7 @@ public class ChannelSwitchEvent implements CarbonEvent, Cancellable {
private String failureMessage; private String failureMessage;
private boolean cancelled = false; private boolean cancelled = false;
public ChannelSwitchEvent(@NonNull final ChatChannel channel, @NonNull final ChatUser user, @Nullable final String failureMessage) { public ChannelSwitchEvent(final @NonNull ChatChannel channel, final @NonNull ChatUser user, @Nullable final String failureMessage) {
this.channel = channel; this.channel = channel;
this.user = user; this.user = user;
this.failureMessage = failureMessage; this.failureMessage = failureMessage;
@@ -22,9 +22,9 @@ public class ChatComponentEvent implements CarbonEvent, Cancellable {
@NonNull @NonNull
private final String originalMessage; private final String originalMessage;
public ChatComponentEvent(@NonNull final ChatUser sender, @Nullable final ChatUser target, public ChatComponentEvent(final @NonNull ChatUser sender, @Nullable final ChatUser target,
@NonNull final ChatChannel chatChannel, @NonNull final TextComponent component, final @NonNull ChatChannel chatChannel, final @NonNull TextComponent component,
@NonNull final String originalMessage) { final @NonNull String originalMessage) {
this.sender = sender; this.sender = sender;
this.target = target; this.target = target;
@@ -58,7 +58,7 @@ public class ChatComponentEvent implements CarbonEvent, Cancellable {
return this.chatChannel; return this.chatChannel;
} }
public void channel(@NonNull final ChatChannel chatChannel) { public void channel(final @NonNull ChatChannel chatChannel) {
this.chatChannel = chatChannel; this.chatChannel = chatChannel;
} }
@@ -67,7 +67,7 @@ public class ChatComponentEvent implements CarbonEvent, Cancellable {
return this.component; return this.component;
} }
public void component(@NonNull final TextComponent component) { public void component(final @NonNull TextComponent component) {
this.component = component; this.component = component;
} }
@@ -21,9 +21,9 @@ public class ChatFormatEvent implements CarbonEvent, Cancellable {
@NonNull @NonNull
private String message; private String message;
public ChatFormatEvent(@NonNull final ChatUser sender, @Nullable final ChatUser target, public ChatFormatEvent(final @NonNull ChatUser sender, @Nullable final ChatUser target,
@NonNull final ChatChannel chatChannel, @Nullable final String format, final @NonNull ChatChannel chatChannel, @Nullable final String format,
@NonNull final String message) { final @NonNull String message) {
this.sender = sender; this.sender = sender;
this.target = target; this.target = target;
@@ -58,7 +58,7 @@ public class ChatFormatEvent implements CarbonEvent, Cancellable {
return this.chatChannel; return this.chatChannel;
} }
public void channel(@NonNull final ChatChannel chatChannel) { public void channel(final @NonNull ChatChannel chatChannel) {
this.chatChannel = chatChannel; this.chatChannel = chatChannel;
} }
@@ -76,7 +76,7 @@ public class ChatFormatEvent implements CarbonEvent, Cancellable {
return this.message; return this.message;
} }
public void message(@NonNull final String message) { public void message(final @NonNull String message) {
this.message = message; this.message = message;
} }
@@ -9,8 +9,8 @@ import org.checkerframework.checker.nullness.qual.NonNull;
public class MessageContextEvent implements CarbonEvent, Cancellable { public class MessageContextEvent implements CarbonEvent, Cancellable {
private @NonNull final ChatChannel channel; private final @NonNull ChatChannel channel;
private @NonNull final ChatUser user; private final @NonNull ChatUser user;
private boolean cancelled = false; private boolean cancelled = false;
public MessageContextEvent(final @NonNull ChatChannel channel, final @NonNull ChatUser user) { public MessageContextEvent(final @NonNull ChatChannel channel, final @NonNull ChatUser user) {
@@ -28,7 +28,7 @@ public class MessageContextEvent implements CarbonEvent, Cancellable {
this.cancelled = cancelled; this.cancelled = cancelled;
} }
public Context context(@NonNull final String key) { public Context context(final @NonNull String key) {
return this.channel.context(key); return this.channel.context(key);
} }
@@ -19,8 +19,8 @@ public class PreChatFormatEvent implements CarbonEvent, Cancellable {
@NonNull @NonNull
private String message; private String message;
public PreChatFormatEvent(@NonNull final ChatUser user, @NonNull final ChatChannel chatChannel, public PreChatFormatEvent(final @NonNull ChatUser user, final @NonNull ChatChannel chatChannel,
@Nullable final String format, @NonNull final String message) { @Nullable final String format, final @NonNull String message) {
this.user = user; this.user = user;
this.chatChannel = chatChannel; this.chatChannel = chatChannel;
@@ -48,7 +48,7 @@ public class PreChatFormatEvent implements CarbonEvent, Cancellable {
return this.chatChannel; return this.chatChannel;
} }
public void channel(@NonNull final ChatChannel chatChannel) { public void channel(final @NonNull ChatChannel chatChannel) {
this.chatChannel = chatChannel; this.chatChannel = chatChannel;
} }
@@ -66,7 +66,7 @@ public class PreChatFormatEvent implements CarbonEvent, Cancellable {
return this.message; return this.message;
} }
public void message(@NonNull final String message) { public void message(final @NonNull String message) {
this.message = message; this.message = message;
} }
@@ -20,9 +20,9 @@ public class PrivateMessageEvent implements CarbonEvent, Cancellable {
private final String message; private final String message;
private boolean cancelled = false; private boolean cancelled = false;
public PrivateMessageEvent(@NonNull final ChatUser sender, @NonNull final ChatUser target, public PrivateMessageEvent(final @NonNull ChatUser sender, final @NonNull ChatUser target,
@NonNull final Component senderComponent, @NonNull final Component targetComponent, final @NonNull Component senderComponent, final @NonNull Component targetComponent,
@NonNull final String message) { final @NonNull String message) {
this.sender = sender; this.sender = sender;
this.target = target; this.target = target;
@@ -9,9 +9,9 @@ import org.checkerframework.checker.nullness.qual.NonNull;
public class ReceiverContextEvent implements CarbonEvent, Cancellable { public class ReceiverContextEvent implements CarbonEvent, Cancellable {
private @NonNull final ChatChannel channel; private final @NonNull ChatChannel channel;
private @NonNull final ChatUser sender; private final @NonNull ChatUser sender;
private @NonNull final ChatUser recipient; private final @NonNull ChatUser recipient;
private boolean cancelled = false; private boolean cancelled = false;
public ReceiverContextEvent(final @NonNull ChatChannel channel, final @NonNull ChatUser sender, final @NonNull ChatUser recipient) { public ReceiverContextEvent(final @NonNull ChatChannel channel, final @NonNull ChatUser sender, final @NonNull ChatUser recipient) {
@@ -20,7 +20,7 @@ public class ReceiverContextEvent implements CarbonEvent, Cancellable {
this.recipient = recipient; this.recipient = recipient;
} }
public Context context(@NonNull final String key) { public Context context(final @NonNull String key) {
return this.channel.context(key); return this.channel.context(key);
} }
@@ -14,11 +14,11 @@ public final class CarbonEvents {
private static final SimpleEventBus<CarbonEvent> EVENT_BUS = new SimpleEventBus<>(CarbonEvent.class); private static final SimpleEventBus<CarbonEvent> EVENT_BUS = new SimpleEventBus<>(CarbonEvent.class);
public static <T extends CarbonEvent> void register(@NonNull final Class<T> clazz, @NonNull final EventSubscriber<T> subscriber) { public static <T extends CarbonEvent> void register(final @NonNull Class<T> clazz, final @NonNull EventSubscriber<T> subscriber) {
EVENT_BUS.register(clazz, subscriber); EVENT_BUS.register(clazz, subscriber);
} }
public static <T extends CarbonEvent> void register(@NonNull final Class<T> clazz, final int priority, final boolean consumeCancelled, @NonNull final Consumer<T> consumer) { public static <T extends CarbonEvent> void register(final @NonNull Class<T> clazz, final int priority, final boolean consumeCancelled, final @NonNull Consumer<T> consumer) {
EVENT_BUS.register(clazz, new EventSubscriber<T>() { EVENT_BUS.register(clazz, new EventSubscriber<T>() {
@Override @Override
public int postOrder() { public int postOrder() {
@@ -31,17 +31,17 @@ public final class CarbonEvents {
} }
@Override @Override
public void invoke(@NonNull final T event) { public void invoke(final @NonNull T event) {
consumer.accept(event); consumer.accept(event);
} }
}); });
} }
public static void unregister(@NonNull final EventSubscriber<? super CarbonEvent> subscriber) { public static void unregister(final @NonNull EventSubscriber<? super CarbonEvent> subscriber) {
EVENT_BUS.unregister(subscriber); EVENT_BUS.unregister(subscriber);
} }
public static PostResult post(@NonNull final CarbonEvent event) { public static PostResult post(final @NonNull CarbonEvent event) {
return EVENT_BUS.post(event); return EVENT_BUS.post(event);
} }
@@ -11,12 +11,12 @@ import java.util.function.Consumer;
public interface MessageService { public interface MessageService {
void registerUserMessageListener(@NonNull final String key, @NonNull final BiConsumer<@NonNull ChatUser, @NonNull ByteArrayDataInput> listener); void registerUserMessageListener(final @NonNull String key, final @NonNull BiConsumer<@NonNull ChatUser, @NonNull ByteArrayDataInput> listener);
void registerUUIDMessageListener(@NonNull final String key, @NonNull final BiConsumer<@NonNull UUID, @NonNull ByteArrayDataInput> listener); void registerUUIDMessageListener(final @NonNull String key, final @NonNull BiConsumer<@NonNull UUID, @NonNull ByteArrayDataInput> listener);
void unregisterMessageListener(@NonNull final String key); void unregisterMessageListener(final @NonNull String key);
void sendMessage(@NonNull final String key, @NonNull final UUID uuid, @NonNull final Consumer<@NonNull ByteArrayDataOutput> consumer); void sendMessage(final @NonNull String key, final @NonNull UUID uuid, final @NonNull Consumer<@NonNull ByteArrayDataOutput> consumer);
} }
@@ -1,14 +1,16 @@
package net.draycia.carbon.api.users; package net.draycia.carbon.api.users;
import com.intellectualsites.commands.sender.CommandSender;
import net.draycia.carbon.api.channels.ChatChannel; import net.draycia.carbon.api.channels.ChatChannel;
import net.kyori.adventure.audience.Audience; import net.kyori.adventure.audience.Audience;
import net.luckperms.api.model.group.Group;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.Collection;
import java.util.Map;
import java.util.UUID; import java.util.UUID;
public interface ChatUser extends Audience, CommandSender { public interface ChatUser extends Audience {
@NonNull UUID uuid(); @NonNull UUID uuid();
@@ -17,7 +19,6 @@ public interface ChatUser extends Audience, CommandSender {
boolean online(); boolean online();
@Override
boolean hasPermission(@NonNull String permission); boolean hasPermission(@NonNull String permission);
@Nullable String nickname(); @Nullable String nickname();
@@ -36,7 +37,7 @@ public interface ChatUser extends Audience, CommandSender {
@Nullable ChatChannel selectedChannel(); @Nullable ChatChannel selectedChannel();
default void selectedChannel(@NonNull final ChatChannel channel) { default void selectedChannel(final @NonNull ChatChannel channel) {
this.selectedChannel(channel, false); this.selectedChannel(channel, false);
} }
@@ -46,6 +47,8 @@ public interface ChatUser extends Audience, CommandSender {
@NonNull UserChannelSettings channelSettings(@NonNull ChatChannel channel); @NonNull UserChannelSettings channelSettings(@NonNull ChatChannel channel);
@NonNull Map<@NonNull String, @NonNull ? extends UserChannelSettings> channelSettings();
boolean spyingwhispers(); boolean spyingwhispers();
default void spyingWhispers(final boolean spyingWhispers) { default void spyingWhispers(final boolean spyingWhispers) {
@@ -90,22 +93,34 @@ public interface ChatUser extends Audience, CommandSender {
void ignoringUser(@NonNull UUID uuid, boolean ignoring, boolean fromRemote); void ignoringUser(@NonNull UUID uuid, boolean ignoring, boolean fromRemote);
default void ignoringUser(@NonNull final UUID uuid, final boolean ignoring) { default void ignoringUser(final @NonNull UUID uuid, final boolean ignoring) {
this.ignoringUser(uuid, ignoring, false); this.ignoringUser(uuid, ignoring, false);
} }
default boolean ignoringUser(@NonNull final ChatUser user) { default boolean ignoringUser(final @NonNull ChatUser user) {
return this.ignoringUser(user.uuid()); return this.ignoringUser(user.uuid());
} }
default void ignoringUser(@NonNull final ChatUser user, final boolean ignoring, final boolean fromRemote) { default void ignoringUser(final @NonNull ChatUser user, final boolean ignoring, final boolean fromRemote) {
this.ignoringUser(user.uuid(), ignoring, fromRemote); this.ignoringUser(user.uuid(), ignoring, fromRemote);
} }
default void ignoringUser(@NonNull final ChatUser user, final boolean ignoring) { default void ignoringUser(final @NonNull ChatUser user, final boolean ignoring) {
this.ignoringUser(user.uuid(), ignoring, false); this.ignoringUser(user.uuid(), ignoring, false);
} }
void sendMessage(@NonNull final ChatUser sender, @NonNull String message); @NonNull Iterable<ChatUser> ignoredChatUsers();
@NonNull Iterable<UUID> ignoredUsers();
boolean hasGroup(@NonNull final String group);
boolean hasGroup(@NonNull final Group group);
@NonNull Collection<@NonNull Group> groups();
@NonNull Group primaryGroup();
void sendMessage(final @NonNull ChatUser sender, @NonNull String message);
} }
-4
View File
@@ -10,10 +10,6 @@ dependencies {
compile project(":CarbonChat-Common") compile project(":CarbonChat-Common")
// Databases
compile 'co.aikar:idb-bukkit:1.0.0-SNAPSHOT'
compile 'com.zaxxer:HikariCP:2.4.1'
// Messaging // Messaging
compile 'io.github.leonardosnt:bungeechannelapi:1.0.0-SNAPSHOT' compile 'io.github.leonardosnt:bungeechannelapi:1.0.0-SNAPSHOT'
@@ -8,6 +8,8 @@ import net.draycia.carbon.api.adventure.CarbonTranslations;
import net.draycia.carbon.api.adventure.MessageProcessor; import net.draycia.carbon.api.adventure.MessageProcessor;
import net.draycia.carbon.api.channels.ChannelRegistry; import net.draycia.carbon.api.channels.ChannelRegistry;
import net.draycia.carbon.api.commands.settings.CommandSettingsRegistry; import net.draycia.carbon.api.commands.settings.CommandSettingsRegistry;
import net.draycia.carbon.api.config.ModerationSettings;
import net.draycia.carbon.api.messaging.MessageService;
import net.draycia.carbon.api.users.ChatUser; import net.draycia.carbon.api.users.ChatUser;
import net.draycia.carbon.common.adventure.FormatType; import net.draycia.carbon.common.adventure.FormatType;
import net.draycia.carbon.common.messaging.EmptyMessageService; import net.draycia.carbon.common.messaging.EmptyMessageService;
@@ -37,7 +39,8 @@ import net.draycia.carbon.common.commands.misc.CommandRegistrar;
import net.draycia.carbon.common.messaging.MessageManager; import net.draycia.carbon.common.messaging.MessageManager;
import net.draycia.carbon.api.users.UserService; import net.draycia.carbon.api.users.UserService;
import net.draycia.carbon.common.users.JSONUserService; import net.draycia.carbon.common.users.JSONUserService;
import net.draycia.carbon.storage.impl.MySQLUserService; import net.draycia.carbon.common.users.MySQLUserService;
import net.draycia.carbon.storage.impl.BukkitChatUser;
import net.draycia.carbon.util.CarbonPlaceholders; import net.draycia.carbon.util.CarbonPlaceholders;
import net.draycia.carbon.util.FunctionalityConstants; import net.draycia.carbon.util.FunctionalityConstants;
import net.draycia.carbon.util.Metrics; import net.draycia.carbon.util.Metrics;
@@ -51,12 +54,15 @@ import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spongepowered.configurate.BasicConfigurationNode; import org.spongepowered.configurate.BasicConfigurationNode;
import org.spongepowered.configurate.objectmapping.ObjectMappingException; import org.spongepowered.configurate.objectmapping.ObjectMappingException;
import org.spongepowered.configurate.yaml.YamlConfigurationLoader; import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Path;
public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat { public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
@@ -68,13 +74,15 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
private CommandSettingsRegistry commandSettings; private CommandSettingsRegistry commandSettings;
private AdventureManager messageProcessor; private AdventureManager messageProcessor;
private UserService userService; private UserService<BukkitChatUser> userService;
private MessageManager messageManager; private MessageManager messageManager;
private FilterContext filterContext; private FilterContext filterContext;
private CarbonTranslations translations; private CarbonTranslations translations;
private Logger logger;
public static final LegacyComponentSerializer LEGACY = public static final LegacyComponentSerializer LEGACY =
LegacyComponentSerializer.builder() LegacyComponentSerializer.builder()
.extractUrls() .extractUrls()
@@ -92,6 +100,8 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
@Override @Override
public void onEnable() { public void onEnable() {
this.logger = LoggerFactory.getLogger(this.getName());
CommandAPI.onEnable(this); CommandAPI.onEnable(this);
final Metrics metrics = new Metrics(this, BSTATS_PLUGIN_ID); final Metrics metrics = new Metrics(this, BSTATS_PLUGIN_ID);
@@ -119,24 +129,25 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
final String storageType = this.getConfig().getString("storage.type"); final String storageType = this.getConfig().getString("storage.type");
if (storageType.equalsIgnoreCase("mysql")) { if (storageType.equalsIgnoreCase("mysql")) {
this.getLogger().info("Enabling MySQL storage!"); this.logger().info("Enabling MySQL storage!");
this.userService = new MySQLUserService(this); this.userService = new MySQLUserService(this);
} else if (storageType.equalsIgnoreCase("json")) { } else if (storageType.equalsIgnoreCase("json")) {
this.getLogger().info("Enabling JSON storage!"); this.logger().info("Enabling JSON storage!");
this.userService = new JSONUserService(this); this.userService = new JSONUserService(this);
} else { } else {
this.getLogger().warning("Invalid storage type selected! Falling back to JSON."); this.logger().error("Invalid storage type selected! Falling back to JSON.");
this.userService = new JSONUserService(this); this.userService = new JSONUserService(this);
} }
// Setup listeners // Setup listeners
this.setupCommands();
this.setupListeners(); this.setupListeners();
this.registerContexts(); this.registerContexts();
new CarbonPlaceholders(this).register(); new CarbonPlaceholders(this).register();
if (!FunctionalityConstants.HAS_HOVER_EVENT_METHOD) { if (!FunctionalityConstants.HAS_HOVER_EVENT_METHOD) {
this.getLogger().warning("Item linking disabled! Please use Paper 1.16.2 #172 or newer."); this.logger().error("Item linking disabled! Please use Paper 1.16.2 #172 or newer.");
} }
} }
@@ -178,9 +189,7 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
// TODO: weeeeee fix this // TODO: weeeeee fix this
throw new IllegalArgumentException("Non-players not supported yet!"); throw new IllegalArgumentException("Non-players not supported yet!");
} }
}, user -> { }, user -> Bukkit.getPlayer(user.uuid()));
return Bukkit.getPlayer(user.uuid());
});
CommandRegistrar.registerCommands(manager); CommandRegistrar.registerCommands(manager);
} catch (final Exception e) { } catch (final Exception e) {
@@ -267,7 +276,7 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
} }
@NonNull @NonNull
public UserService userService() { public UserService<BukkitChatUser> userService() {
return this.userService; return this.userService;
} }
@@ -286,8 +295,29 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
return this.translations; return this.translations;
} }
@Override
public @NonNull ModerationSettings moderationSettings() {
return this.moderationSettings;
}
@Override @Override
public @NonNull MessageProcessor messageProcessor() { public @NonNull MessageProcessor messageProcessor() {
return this.messageProcessor; return this.messageProcessor;
} }
@Override
public @NonNull MessageService messageService() {
return this.messageManager().messageService();
}
@Override
public @NonNull Logger logger() {
return this.logger;
}
@Override
public @NonNull Path dataFolder() {
return this.getDataFolder().toPath();
}
} }
@@ -1,7 +1,8 @@
package net.draycia.carbon.channels; package net.draycia.carbon.channels;
import net.draycia.carbon.api.CarbonChat;
import net.draycia.carbon.common.channels.ChannelSettings;
import net.draycia.carbon.util.CarbonUtils; import net.draycia.carbon.util.CarbonUtils;
import net.draycia.carbon.CarbonChatBukkit;
import net.draycia.carbon.api.channels.ChatChannel; import net.draycia.carbon.api.channels.ChatChannel;
import net.draycia.carbon.api.events.misc.CarbonEvents; import net.draycia.carbon.api.events.misc.CarbonEvents;
import net.draycia.carbon.api.events.ChatComponentEvent; import net.draycia.carbon.api.events.ChatComponentEvent;
@@ -16,17 +17,14 @@ import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextColor; import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.Bukkit; import net.luckperms.api.model.group.Group;
import org.bukkit.OfflinePlayer;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.UUID;
import java.util.regex.Pattern; import java.util.regex.Pattern;
public class CarbonChatChannel implements ChatChannel { public class CarbonChatChannel implements ChatChannel {
@@ -35,24 +33,29 @@ public class CarbonChatChannel implements ChatChannel {
private final String key; private final String key;
@NonNull @NonNull
private final CarbonChatBukkit carbonChat; private final CarbonChat carbonChat;
@Nullable @NonNull
private final ConfigurationSection config; private final ChannelSettings settings;
public CarbonChatChannel(@NonNull final String key, @NonNull final CarbonChatBukkit carbonChat, @Nullable final ConfigurationSection config) { public CarbonChatChannel(final @NonNull String key, final @NonNull CarbonChat carbonChat,
@Nullable final ChannelSettings settings) {
this.key = key; this.key = key;
this.carbonChat = carbonChat; this.carbonChat = carbonChat;
this.config = config; this.settings = settings;
}
public @NonNull ChannelSettings settings() {
return this.settings;
} }
@NonNull @NonNull
public CarbonChatBukkit carbonChat() { public CarbonChat carbonChat() {
return this.carbonChat; return this.carbonChat;
} }
@Override @Override
public boolean testContext(@NonNull final ChatUser sender, @NonNull final ChatUser target) { public boolean testContext(final @NonNull ChatUser sender, final @NonNull ChatUser target) {
final ReceiverContextEvent event = new ReceiverContextEvent(this, sender, target); final ReceiverContextEvent event = new ReceiverContextEvent(this, sender, target);
CarbonEvents.post(event); CarbonEvents.post(event);
@@ -61,7 +64,7 @@ public class CarbonChatChannel implements ChatChannel {
} }
@Override @Override
public boolean canPlayerUse(@NonNull final ChatUser user) { public boolean canPlayerUse(final @NonNull ChatUser user) {
return user.permissible() && user.hasPermission("carbonchat.channels." + this.name() + ".use"); return user.permissible() && user.hasPermission("carbonchat.channels." + this.name() + ".use");
} }
@@ -70,40 +73,38 @@ public class CarbonChatChannel implements ChatChannel {
public List<@NonNull ChatUser> audiences() { public List<@NonNull ChatUser> audiences() {
final List<ChatUser> audience = new ArrayList<>(); final List<ChatUser> audience = new ArrayList<>();
for (final Player player : Bukkit.getOnlinePlayers()) { for (final ChatUser user : this.carbonChat.userService().onlineUsers()) {
final ChatUser playerUser = this.carbonChat.userService().wrap(player.getUniqueId()); if (this.canPlayerSee(user, true)) {
audience.add(user);
if (this.canPlayerSee(playerUser, true)) {
audience.add(playerUser);
} }
} }
return audience; return audience;
} }
private void updateUserNickname(@NonNull final ChatUser user) { // private void updateUserNickname(final @NonNull ChatUser user) {
final Player player = Bukkit.getPlayer(user.uuid()); // final Player player = Bukkit.getPlayer(user.uuid());
//
if (player != null) { // if (player != null) {
String nickname = user.nickname(); // String nickname = user.nickname();
//
if (nickname != null) { // if (nickname != null) {
final Component component = this.carbonChat.messageProcessor().processMessage(nickname); // final Component component = this.carbonChat.messageProcessor().processMessage(nickname);
nickname = CarbonChatBukkit.LEGACY.serialize(component); // nickname = CarbonChat.LEGACY.serialize(component);
//
player.setDisplayName(nickname); // player.setDisplayName(nickname);
//
if (this.carbonChat.getConfig().getBoolean("nicknames-set-tab-name")) { // if (this.carbonChat.getConfig().getBoolean("nicknames-set-tab-name")) {
player.setPlayerListName(nickname); // player.setPlayerListName(nickname);
} // }
} // }
} // }
} // }
@Override @Override
@NonNull @NonNull
public Component sendMessage(@NonNull final ChatUser user, @NonNull final Collection<@NonNull ChatUser> recipients, @NonNull final String message, final boolean fromRemote) { public Component sendMessage(final @NonNull ChatUser user, final @NonNull Collection<@NonNull ChatUser> recipients, final @NonNull String message, final boolean fromRemote) {
this.updateUserNickname(user); //this.updateUserNickname(user);
final MessageContextEvent event = new MessageContextEvent(this, user); final MessageContextEvent event = new MessageContextEvent(this, user);
@@ -132,13 +133,7 @@ public class CarbonChatChannel implements ChatChannel {
if (user.nickname() != null) { if (user.nickname() != null) {
displayName = user.nickname(); displayName = user.nickname();
} else { } else {
final OfflinePlayer player = Bukkit.getOfflinePlayer(user.uuid()); displayName = user.displayName();
if (player.isOnline()) {
displayName = player.getPlayer().getDisplayName();
} else {
displayName = player.getName();
}
} }
// Iterate through players who should receive messages in this channel // Iterate through players who should receive messages in this channel
@@ -198,13 +193,8 @@ public class CarbonChatChannel implements ChatChannel {
CarbonEvents.post(consoleEvent); CarbonEvents.post(consoleEvent);
// Route message to bungee / discord (if message originates from this server) if (user.online() && !fromRemote && this.crossServer()) {
// Use instanceof and not isOnline, if this message originates from another then the instanceof will this.sendMessageToBungee(user.uuid(), consoleEvent.component());
// fail, but isOnline may succeed if the player is online on both servers (somehow).
final Player player = Bukkit.getPlayer(user.uuid());
if (player != null && !fromRemote && this.crossServer()) {
this.sendMessageToBungee(player, consoleEvent.component());
} }
return consoleEvent.component(); return consoleEvent.component();
@@ -212,12 +202,12 @@ public class CarbonChatChannel implements ChatChannel {
@Override @Override
@NonNull @NonNull
public Component sendMessage(@NonNull final ChatUser user, @NonNull final String message, final boolean fromRemote) { public Component sendMessage(final @NonNull ChatUser user, final @NonNull String message, final boolean fromRemote) {
return this.sendMessage(user, this.audiences(), message, fromRemote); return this.sendMessage(user, this.audiences(), message, fromRemote);
} }
@Nullable @Nullable
public String format(@NonNull final ChatUser user) { public String format(final @NonNull ChatUser user) {
for (final String group : this.groupOverrides()) { for (final String group : this.groupOverrides()) {
if (this.userHasGroup(user, group)) { if (this.userHasGroup(user, group)) {
final String format = this.format(group); final String format = this.format(group);
@@ -235,18 +225,12 @@ public class CarbonChatChannel implements ChatChannel {
} }
} }
private boolean userHasGroup(@NonNull final ChatUser user, @NonNull final String group) { private boolean userHasGroup(final @NonNull ChatUser user, final @NonNull String group) {
if (user.permissible()) { if (user.hasGroup(group)) {
if (this.carbonChat.permission().playerInGroup(Bukkit.getPlayer(user.uuid()), group)) {
return true; return true;
} }
} else {
if (this.carbonChat.permission().playerInGroup(null, Bukkit.getOfflinePlayer(user.uuid()), group)) {
return true;
}
}
if (user.permissible() && this.permissionGroupMatching()) { if (this.permissionGroupMatching()) {
return user.hasPermission("carbonchat.group." + group); return user.hasPermission("carbonchat.group." + group);
} }
@@ -254,16 +238,8 @@ public class CarbonChatChannel implements ChatChannel {
} }
@Nullable @Nullable
private String firstFoundUserFormat(@NonNull final ChatUser user) { private String firstFoundUserFormat(final @NonNull ChatUser user) {
final String[] playerGroups; for (final Group group : user.groups()) {
if (user.permissible()) {
playerGroups = this.carbonChat.permission().getPlayerGroups(Bukkit.getPlayer(user.uuid()));
} else {
playerGroups = this.carbonChat.permission().getPlayerGroups(null, Bukkit.getOfflinePlayer(user.uuid()));
}
for (final String group : playerGroups) {
final String groupFormat = this.format(group); final String groupFormat = this.format(group);
if (groupFormat != null) { if (groupFormat != null) {
@@ -275,15 +251,8 @@ public class CarbonChatChannel implements ChatChannel {
} }
@Nullable @Nullable
private String primaryGroupFormat(@NonNull final ChatUser user) { private String primaryGroupFormat(final @NonNull ChatUser user) {
final String primaryGroup; final Group primaryGroup = user.primaryGroup();
if (user.permissible()) {
primaryGroup = this.carbonChat.permission().getPrimaryGroup(Bukkit.getPlayer(user.uuid()));
} else {
primaryGroup = this.carbonChat.permission().getPrimaryGroup(null, Bukkit.getOfflinePlayer(user.uuid()));
}
final String primaryGroupFormat = this.format(primaryGroup); final String primaryGroupFormat = this.format(primaryGroup);
if (primaryGroupFormat != null) { if (primaryGroupFormat != null) {
@@ -300,11 +269,17 @@ public class CarbonChatChannel implements ChatChannel {
@Override @Override
@Nullable @Nullable
public String format(@NonNull final String group) { public String format(final @NonNull Group group) {
return this.getString("formats." + group); return this.format(group.getName());
} }
private boolean isUserSpying(@NonNull final ChatUser sender, @NonNull final ChatUser target) { @Override
@Nullable
public String format(final @NonNull String group) {
return this.settings().formats().get("formats." + group);
}
private boolean isUserSpying(final @NonNull ChatUser sender, final @NonNull ChatUser target) {
if (!this.canPlayerSee(sender, target, false)) { if (!this.canPlayerSee(sender, target, false)) {
return target.channelSettings(this).spying(); return target.channelSettings(this).spying();
} }
@@ -313,7 +288,7 @@ public class CarbonChatChannel implements ChatChannel {
} }
@Override @Override
public void sendComponent(@NonNull final ChatUser player, @NonNull final Component component) { public void sendComponent(final @NonNull ChatUser player, final @NonNull Component component) {
for (final ChatUser user : this.audiences()) { for (final ChatUser user : this.audiences()) {
if (!user.ignoringUser(player)) { if (!user.ignoringUser(player)) {
user.sendMessage(component); user.sendMessage(component);
@@ -321,15 +296,15 @@ public class CarbonChatChannel implements ChatChannel {
} }
} }
public void sendMessageToBungee(@NonNull final Player player, @NonNull final Component component) { public void sendMessageToBungee(final @NonNull UUID uuid, final @NonNull Component component) {
this.carbonChat.messageManager().sendMessage("channel-component", player.getUniqueId(), byteArray -> { this.carbonChat.messageService().sendMessage("channel-component", uuid, byteArray -> {
byteArray.writeUTF(this.key()); byteArray.writeUTF(this.key());
byteArray.writeUTF(this.carbonChat.messageProcessor().audiences().gsonSerializer().serialize(component)); byteArray.writeUTF(this.carbonChat.messageProcessor().audiences().gsonSerializer().serialize(component));
}); });
} }
@Override @Override
public boolean canPlayerSee(@NonNull final ChatUser target, final boolean checkSpying) { public boolean canPlayerSee(final @NonNull ChatUser target, final boolean checkSpying) {
if (checkSpying && target.permissible() && target.hasPermission("carbonchat.spy." + this.name())) { if (checkSpying && target.permissible() && target.hasPermission("carbonchat.spy." + this.name())) {
if (target.channelSettings(this).spying()) { if (target.channelSettings(this).spying()) {
return true; return true;
@@ -347,7 +322,7 @@ public class CarbonChatChannel implements ChatChannel {
return true; return true;
} }
public boolean canPlayerSee(@NonNull final ChatUser sender, @NonNull final ChatUser target, final boolean checkSpying) { public boolean canPlayerSee(final @NonNull ChatUser sender, final @NonNull ChatUser target, final boolean checkSpying) {
if (!this.canPlayerSee(target, checkSpying)) { if (!this.canPlayerSee(target, checkSpying)) {
return false; return false;
@@ -362,20 +337,20 @@ public class CarbonChatChannel implements ChatChannel {
@Override @Override
@Nullable @Nullable
public TextColor channelColor(@NonNull final ChatUser user) { public TextColor channelColor(final @NonNull ChatUser user) {
final TextColor userColor = user.channelSettings(this).color(); final TextColor userColor = user.channelSettings(this).color();
if (userColor != null) { if (userColor != null) {
return userColor; return userColor;
} }
final String input = this.getString("color"); final String input = this.settings().color();
final TextColor color = CarbonUtils.parseColor(user, input); final TextColor color = CarbonUtils.parseColor(user, input);
if (color == null && this.carbonChat.getConfig().getBoolean("show-tips")) { if (color == null && this.carbonChat.getConfig().getBoolean("show-tips")) {
this.carbonChat.getLogger().warning("Tip: Channel color found (" + input + ") is invalid!"); this.carbonChat.logger().error("Tip: Channel color found (" + input + ") is invalid!");
this.carbonChat.getLogger().warning("Falling back to #FFFFFF"); this.carbonChat.logger().error("Falling back to #FFFFFF");
return NamedTextColor.WHITE; return NamedTextColor.WHITE;
} }
@@ -384,233 +359,133 @@ public class CarbonChatChannel implements ChatChannel {
} }
@Nullable @Nullable
private String defaultFormatName() { public String defaultFormatName() {
return this.getString("default-group"); return this.settings().defaultFormatName();
} }
@Override @Override
public boolean isDefault() { public boolean isDefault() {
if (this.config != null && this.config.contains("default")) { return this.settings().isDefault();
return this.config.getBoolean("default");
}
return false;
} }
@Override @Override
public boolean ignorable() { public boolean ignorable() {
return this.getBoolean("ignorable"); return this.settings().ignorable();
} }
@Override @Override
public boolean crossServer() { public boolean crossServer() {
return this.getBoolean("is-cross-server"); return this.settings().crossServer();
} }
@Override @Override
public boolean honorsRecipientList() { public boolean honorsRecipientList() {
return this.getBoolean("honors-recipient-list"); return this.settings().honorsRecipientList();
} }
@Override @Override
public boolean permissionGroupMatching() { public boolean permissionGroupMatching() {
return this.getBoolean("permission-group-matching"); return this.settings().permissionGroupMatching();
} }
@Override @Override
@NonNull @NonNull
public List<@NonNull String> groupOverrides() { public List<@NonNull String> groupOverrides() {
return this.getStringList("group-overrides"); return this.settings().groupOverrides();
} }
@Override @Override
@NonNull @NonNull
public String name() { public String name() {
final String name = this.getString("name"); return this.settings().name();
return name == null ? this.key : name;
} }
@Override @Override
@Nullable @Nullable
public String messagePrefix() { public String messagePrefix() {
if (this.config != null && this.config.contains("message-prefix")) { return this.settings().messagePrefix();
return this.config.getString("message-prefix");
}
return null;
} }
@Override @Override
@Nullable @Nullable
public String switchMessage() { public String switchMessage() {
return this.getString("switch-message"); return this.settings().switchMessage();
} }
@Override @Override
@Nullable @Nullable
public String switchOtherMessage() { public String switchOtherMessage() {
return this.getString("switch-other-message"); return this.settings().switchOtherMessage();
} }
@Override @Override
@Nullable @Nullable
public String switchFailureMessage() { public String switchFailureMessage() {
return this.getString("switch-failure-message"); return this.settings().switchFailureMessage();
} }
@Override @Override
@Nullable @Nullable
public String cannotIgnoreMessage() { public String cannotIgnoreMessage() {
return this.getString("cannot-ignore-message"); return this.settings().cannotIgnoreMessage();
} }
@Override @Override
@Nullable @Nullable
public String toggleOffMessage() { public String toggleOffMessage() {
return this.getString("toggle-off-message"); return this.settings().toggleOffMessage();
} }
@Override @Override
@Nullable @Nullable
public String toggleOnMessage() { public String toggleOnMessage() {
return this.getString("toggle-on-message"); return this.settings().toggleOnMessage();
} }
@Override @Override
@Nullable @Nullable
public String toggleOtherOnMessage() { public String toggleOtherOnMessage() {
return this.getString("toggle-other-on"); return this.settings().toggleOtherOnMessage();
} }
@Override @Override
@Nullable @Nullable
public String toggleOtherOffMessage() { public String toggleOtherOffMessage() {
return this.getString("toggle-other-off"); return this.settings().toggleOtherOffMessage();
} }
@Override @Override
@Nullable @Nullable
public String cannotUseMessage() { public String cannotUseMessage() {
return this.getString("cannot-use-channel"); return this.settings().cannotUseMessage();
} }
@Override @Override
public boolean primaryGroupOnly() { public boolean primaryGroupOnly() {
return this.getBoolean("primary-group-only"); return this.settings().primaryGroupOnly();
} }
@Override @Override
public boolean shouldCancelChatEvent() { public boolean shouldCancelChatEvent() {
return this.getBoolean("cancel-message-event"); return this.settings().shouldCancelChatEvent();
} }
@Override @Override
@NonNull @NonNull
public List<@NonNull Pattern> itemLinkPatterns() { public List<@NonNull Pattern> itemLinkPatterns() {
final ArrayList<Pattern> itemPatterns = new ArrayList<>(); return this.settings().itemLinkPatterns();
for (final String entry : this.carbonChat.getConfig().getStringList("item-link-placeholders")) {
itemPatterns.add(Pattern.compile(Pattern.quote(entry)));
}
return itemPatterns;
} }
@Override @Override
@Nullable @Nullable
public Context context(@NonNull final String key) { public String aliases() {
final ConfigurationSection section = this.config == null ? null : this.config.getConfigurationSection("contexts"); return this.settings().aliases();
if (section == null) {
final ConfigurationSection defaultSection = this.carbonChat.getConfig().getConfigurationSection("default");
if (defaultSection == null) {
return null;
}
final ConfigurationSection defaultContexts = defaultSection.getConfigurationSection("contexts");
if (defaultContexts == null) {
return null;
}
final Object value = defaultContexts.get(key);
if (value != null) {
return new Context(key, value);
}
}
final Object value = section.get(key);
if (value == null) {
return null;
}
return new Context(key, value);
} }
@Override
@Nullable @Nullable
@SuppressWarnings("checkstyle:MethodName") public Context context(final @NonNull String key) {
private String getString(@NonNull final String key) { return this.settings().contexts().get(key);
if (this.config != null && this.config.contains(key)) {
return this.config.getString(key);
}
final ConfigurationSection defaultSection = this.carbonChat.getConfig().getConfigurationSection("default");
if (defaultSection != null && defaultSection.contains(key)) {
return defaultSection.getString(key);
}
return null;
}
@NonNull
@SuppressWarnings("checkstyle:MethodName")
private List<@NonNull String> getStringList(@NonNull final String key) {
if (this.config != null && this.config.contains(key)) {
return this.config.getStringList(key);
}
final ConfigurationSection defaultSection = this.carbonChat.getConfig().getConfigurationSection("default");
if (defaultSection != null && defaultSection.contains(key)) {
return defaultSection.getStringList(key);
}
return Collections.emptyList();
}
@SuppressWarnings("checkstyle:MethodName")
private boolean getBoolean(@NonNull final String key) {
if (this.config != null && this.config.contains(key)) {
return this.config.getBoolean(key);
}
final ConfigurationSection defaultSection = this.carbonChat.getConfig().getConfigurationSection("default");
if (defaultSection != null && defaultSection.contains(key)) {
return defaultSection.getBoolean(key);
}
return false;
}
@SuppressWarnings("checkstyle:MethodName")
private double getDouble(@NonNull final String key) {
if (this.config != null && this.config.contains(key)) {
return this.config.getDouble(key);
}
final ConfigurationSection defaultSection = this.carbonChat.getConfig().getConfigurationSection("default");
if (defaultSection != null && defaultSection.contains(key)) {
return defaultSection.getDouble(key);
}
return 0;
} }
@Override @Override
@@ -619,15 +494,4 @@ public class CarbonChatChannel implements ChatChannel {
return this.key; return this.key;
} }
@Override
@Nullable
public String aliases() {
final String aliases = this.getString("aliases");
if (aliases == null) {
return this.key();
}
return aliases;
}
} }
@@ -16,7 +16,7 @@ public class EconomyContext {
@NonNull @NonNull
private final Economy economy; private final Economy economy;
public EconomyContext(@NonNull final CarbonChatBukkit carbonChat) { public EconomyContext(final @NonNull CarbonChatBukkit carbonChat) {
this.carbonChat = carbonChat; this.carbonChat = carbonChat;
this.economy = this.carbonChat.getServer().getServicesManager().getRegistration(Economy.class).getProvider(); this.economy = this.carbonChat.getServer().getServicesManager().getRegistration(Economy.class).getProvider();
@@ -29,7 +29,7 @@ public class FilterContext {
@NonNull @NonNull
private final List<@NonNull Pattern> blockedWords = new ArrayList<>(); private final List<@NonNull Pattern> blockedWords = new ArrayList<>();
public FilterContext(@NonNull final CarbonChat carbonChat) { public FilterContext(final @NonNull CarbonChat carbonChat) {
this.carbonChat = carbonChat; this.carbonChat = carbonChat;
this.reloadFilters(); this.reloadFilters();
@@ -103,7 +103,7 @@ public class FilterContext {
} }
} }
private boolean channelUsesFilter(@NonNull final ChatChannel chatChannel) { private boolean channelUsesFilter(final @NonNull ChatChannel chatChannel) {
final Context context = chatChannel.context("filter"); final Context context = chatChannel.context("filter");
if (context == null) { if (context == null) {
@@ -27,7 +27,7 @@ public final class TownyContext implements Listener {
@NonNull @NonNull
private final CarbonChatBukkit carbonChat; private final CarbonChatBukkit carbonChat;
public TownyContext(@NonNull final CarbonChatBukkit carbonChat) { public TownyContext(final @NonNull CarbonChatBukkit carbonChat) {
this.carbonChat = carbonChat; this.carbonChat = carbonChat;
CarbonEvents.register(ReceiverContextEvent.class, event -> { CarbonEvents.register(ReceiverContextEvent.class, event -> {
@@ -94,7 +94,7 @@ public final class TownyContext implements Listener {
} }
} }
public boolean isInTown(@NonNull final ChatUser user) { public boolean isInTown(final @NonNull ChatUser user) {
try { try {
return TownyAPI.getInstance().getDataSource().getResident(Bukkit.getPlayer(user.uuid()).getName()).hasTown(); return TownyAPI.getInstance().getDataSource().getResident(Bukkit.getPlayer(user.uuid()).getName()).hasTown();
} catch (final NotRegisteredException exception) { } catch (final NotRegisteredException exception) {
@@ -104,7 +104,7 @@ public final class TownyContext implements Listener {
return false; return false;
} }
public boolean isInSameTown(@NonNull final ChatUser user1, @NonNull final ChatUser user2) { public boolean isInSameTown(final @NonNull ChatUser user1, final @NonNull ChatUser user2) {
if (Bukkit.getPlayer(user1.uuid()) == null || Bukkit.getPlayer(user2.uuid()) == null) { if (Bukkit.getPlayer(user1.uuid()) == null || Bukkit.getPlayer(user2.uuid()) == null) {
return false; return false;
} }
@@ -47,7 +47,7 @@ public final class WorldGuardContext {
}); });
} }
private boolean isInRegionOrRegions(@NonNull final Context context, @NonNull final Player player) { private boolean isInRegionOrRegions(final @NonNull Context context, final @NonNull Player player) {
if (context.isString()) { if (context.isString()) {
return this.isInRegion(context.asString(), player); return this.isInRegion(context.asString(), player);
} }
@@ -63,7 +63,7 @@ public final class WorldGuardContext {
return false; return false;
} }
public boolean testContext(@NonNull final Player sender, @NonNull final Player target, @NonNull final Context context) { public boolean testContext(final @NonNull Player sender, final @NonNull Player target, final @NonNull Context context) {
boolean user1InRegion = false; boolean user1InRegion = false;
boolean user2InRegion = false; boolean user2InRegion = false;
@@ -89,7 +89,7 @@ public final class WorldGuardContext {
return user1InRegion && user2InRegion; return user1InRegion && user2InRegion;
} }
public boolean isInSameRegion(@NonNull final Player user1, @NonNull final Player user2) { public boolean isInSameRegion(final @NonNull Player user1, final @NonNull Player user2) {
final Location user1Location = BukkitAdapter.adapt(user1.getLocation()); final Location user1Location = BukkitAdapter.adapt(user1.getLocation());
final Location user2Location = BukkitAdapter.adapt(user2.getLocation()); final Location user2Location = BukkitAdapter.adapt(user2.getLocation());
@@ -108,7 +108,7 @@ public final class WorldGuardContext {
return false; return false;
} }
public boolean isInRegion(@NonNull final String region, @NonNull final Player player) { public boolean isInRegion(final @NonNull String region, final @NonNull Player player) {
final RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer(); final RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
final World world = BukkitAdapter.adapt(player.getWorld()); final World world = BukkitAdapter.adapt(player.getWorld());
final ProtectedRegion protection = container.get(world).getRegion(region); final ProtectedRegion protection = container.get(world).getRegion(region);
@@ -116,7 +116,7 @@ public final class WorldGuardContext {
return this.isInRegion(protection, player); return this.isInRegion(protection, player);
} }
public boolean isInRegion(@NonNull final ProtectedRegion region, @NonNull final Player player) { public boolean isInRegion(final @NonNull ProtectedRegion region, final @NonNull Player player) {
final org.bukkit.Location location = player.getLocation(); final org.bukkit.Location location = player.getLocation();
return region.contains(location.getBlockX(), location.getBlockY(), location.getBlockZ()); return region.contains(location.getBlockX(), location.getBlockY(), location.getBlockZ());
@@ -25,7 +25,7 @@ public final class mcMMOContext implements Listener {
@NonNull @NonNull
private static final String KEY = "mcmmo-party"; private static final String KEY = "mcmmo-party";
public mcMMOContext(@NonNull final CarbonChatBukkit carbonChat) { public mcMMOContext(final @NonNull CarbonChatBukkit carbonChat) {
this.carbonChat = carbonChat; this.carbonChat = carbonChat;
CarbonEvents.register(ReceiverContextEvent.class, PostOrders.NORMAL, false, event -> { CarbonEvents.register(ReceiverContextEvent.class, PostOrders.NORMAL, false, event -> {
@@ -96,11 +96,11 @@ public final class mcMMOContext implements Listener {
} }
} }
public boolean isInParty(@NonNull final ChatUser user) { public boolean isInParty(final @NonNull ChatUser user) {
return PartyAPI.inParty(Bukkit.getPlayer(user.uuid())); return PartyAPI.inParty(Bukkit.getPlayer(user.uuid()));
} }
public boolean isInSameParty(@NonNull final ChatUser user1, @NonNull final ChatUser user2) { public boolean isInSameParty(final @NonNull ChatUser user1, final @NonNull ChatUser user2) {
if (Bukkit.getPlayer(user1.uuid()) == null || Bukkit.getPlayer(user2.uuid()) == null) { if (Bukkit.getPlayer(user1.uuid()) == null || Bukkit.getPlayer(user2.uuid()) == null) {
return false; return false;
} }
@@ -22,13 +22,13 @@ public class BukkitChatListener implements Listener {
@NonNull @NonNull
private final CarbonChatBukkit carbonChat; private final CarbonChatBukkit carbonChat;
public BukkitChatListener(@NonNull final CarbonChatBukkit carbonChat) { public BukkitChatListener(final @NonNull CarbonChatBukkit carbonChat) {
this.carbonChat = carbonChat; this.carbonChat = carbonChat;
} }
// Chat messages // Chat messages
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerchat(@NonNull final AsyncPlayerChatEvent event) { public void onPlayerchat(final @NonNull AsyncPlayerChatEvent event) {
final ChatUser user = this.carbonChat.userService().wrap(event.getPlayer().getUniqueId()); final ChatUser user = this.carbonChat.userService().wrap(event.getPlayer().getUniqueId());
ChatChannel channel = user.selectedChannel(); ChatChannel channel = user.selectedChannel();
@@ -92,9 +92,9 @@ public class BukkitChatListener implements Listener {
this.carbonChat.messageProcessor().audiences().console().sendMessage(component); this.carbonChat.messageProcessor().audiences().console().sendMessage(component);
if (this.carbonChat.getConfig().getBoolean("show-tips")) { if (this.carbonChat.getConfig().getBoolean("show-tips")) {
this.carbonChat.getLogger().info("Tip: Sync chat event! I cannot set the message format due to this. :("); this.carbonChat.logger().info("Tip: Sync chat event! I cannot set the message format due to this. :(");
this.carbonChat.getLogger().info("Tip: To 'solve' this, do a binary search and see which plugin is triggering"); this.carbonChat.logger().info("Tip: To 'solve' this, do a binary search and see which plugin is triggering");
this.carbonChat.getLogger().info("Tip: sync chat events and causing this, and let that plugin author know."); this.carbonChat.logger().info("Tip: sync chat events and causing this, and let that plugin author know.");
} }
}); });
} }
@@ -26,32 +26,32 @@ public class ChannelManager {
@MonotonicNonNull @MonotonicNonNull
private String defaultChannelKey = null; private String defaultChannelKey = null;
public ChannelManager(@NonNull final CarbonChatBukkit carbonChat) { public ChannelManager(final @NonNull CarbonChatBukkit carbonChat) {
this.carbonChat = carbonChat; this.carbonChat = carbonChat;
this.registry = new ChannelRegistry(); this.registry = new ChannelRegistry();
this.reload(); this.reload();
} }
public @Nullable ChatChannel loadChannel(@NonNull final String key, @NonNull final ConfigurationSection section) { public @Nullable ChatChannel loadChannel(final @NonNull String key, final @NonNull ConfigurationSection section) {
final ChatChannel channel = new CarbonChatChannel(key, this.carbonChat, section); final ChatChannel channel = new CarbonChatChannel(key, this.carbonChat, section);
final String name = section.getString("name"); final String name = section.getString("name");
if (name != null && name.length() > 16) { if (name != null && name.length() > 16) {
this.carbonChat.getLogger().warning("Channel name [" + name + "] too long! Max length: 16."); this.carbonChat.logger().error("Channel name [" + name + "] too long! Max length: 16.");
this.carbonChat.getLogger().warning("Skipping channel, please check your settings!"); this.carbonChat.logger().error("Skipping channel, please check your settings!");
return null; return null;
} }
return channel; return channel;
} }
public void registerChannel(@NonNull final ChatChannel channel) { public void registerChannel(final @NonNull ChatChannel channel) {
this.registry().register(channel.key(), channel); this.registry().register(channel.key(), channel);
if (channel.isDefault() && this.defaultChannelKey == null) { if (channel.isDefault() && this.defaultChannelKey == null) {
this.carbonChat.getLogger().info("Default channel registered: " + channel.name()); this.carbonChat.logger().info("Default channel registered: " + channel.name());
this.defaultChannelKey = channel.key(); this.defaultChannelKey = channel.key();
} }
@@ -101,7 +101,7 @@ public class ChannelManager {
prefix = ""; prefix = "";
} }
this.carbonChat.getLogger().info("Registering channel: " + prefix + channel.name()); this.carbonChat.logger().info("Registering channel: " + prefix + channel.name());
} }
} }
} }
@@ -33,7 +33,7 @@ public class BungeeMessageService implements MessageService {
@NonNull @NonNull
private final UUID serverUUID = UUID.randomUUID(); private final UUID serverUUID = UUID.randomUUID();
public BungeeMessageService(@NonNull final CarbonChatBukkit carbonChat) { public BungeeMessageService(final @NonNull CarbonChatBukkit carbonChat) {
this.carbonChat = carbonChat; this.carbonChat = carbonChat;
this.carbonChat.getServer().getMessenger().registerOutgoingPluginChannel(carbonChat, "BungeeCord"); this.carbonChat.getServer().getMessenger().registerOutgoingPluginChannel(carbonChat, "BungeeCord");
@@ -65,7 +65,7 @@ public class BungeeMessageService implements MessageService {
}); });
} }
private void receiveMessage(@NonNull final UUID uuid, @NonNull final String key, @NonNull final ByteArrayDataInput value) { private void receiveMessage(final @NonNull UUID uuid, final @NonNull String key, final @NonNull ByteArrayDataInput value) {
final ChatUser user = this.carbonChat.userService().wrapIfLoaded(uuid); final ChatUser user = this.carbonChat.userService().wrapIfLoaded(uuid);
if (user != null) { if (user != null) {
@@ -84,23 +84,23 @@ public class BungeeMessageService implements MessageService {
} }
@Override @Override
public void registerUserMessageListener(@NonNull final String key, @NonNull final BiConsumer<@NonNull ChatUser, @NonNull ByteArrayDataInput> listener) { public void registerUserMessageListener(final @NonNull String key, final @NonNull BiConsumer<@NonNull ChatUser, @NonNull ByteArrayDataInput> listener) {
this.userLoadedListeners.put(key, listener); this.userLoadedListeners.put(key, listener);
} }
@Override @Override
public void registerUUIDMessageListener(@NonNull final String key, @NonNull final BiConsumer<@NonNull UUID, @NonNull ByteArrayDataInput> listener) { public void registerUUIDMessageListener(final @NonNull String key, final @NonNull BiConsumer<@NonNull UUID, @NonNull ByteArrayDataInput> listener) {
this.userNotLoadedListeners.put(key, listener); this.userNotLoadedListeners.put(key, listener);
} }
@Override @Override
public void unregisterMessageListener(@NonNull final String key) { public void unregisterMessageListener(final @NonNull String key) {
this.userLoadedListeners.remove(key); this.userLoadedListeners.remove(key);
this.userNotLoadedListeners.remove(key); this.userNotLoadedListeners.remove(key);
} }
@Override @Override
public void sendMessage(@NonNull final String key, @NonNull final UUID uuid, @NonNull final Consumer<ByteArrayDataOutput> consumer) { public void sendMessage(final @NonNull String key, final @NonNull UUID uuid, final @NonNull Consumer<ByteArrayDataOutput> consumer) {
final ByteArrayDataOutput msg = ByteStreams.newDataOutput(); final ByteArrayDataOutput msg = ByteStreams.newDataOutput();
msg.writeLong(this.serverUUID.getMostSignificantBits()); msg.writeLong(this.serverUUID.getMostSignificantBits());
@@ -14,7 +14,11 @@ import net.kyori.adventure.audience.ForwardingAudience;
import net.kyori.adventure.key.Key; import net.kyori.adventure.key.Key;
import net.kyori.adventure.sound.Sound; import net.kyori.adventure.sound.Sound;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.luckperms.api.LuckPerms;
import net.luckperms.api.LuckPermsProvider; import net.luckperms.api.LuckPermsProvider;
import net.luckperms.api.model.group.Group;
import net.luckperms.api.model.user.User;
import net.luckperms.api.query.QueryOptions;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@@ -23,6 +27,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@@ -55,7 +60,7 @@ public class BukkitChatUser implements ChatUser, ForwardingAudience {
this.carbonChat = (CarbonChatBukkit) Bukkit.getPluginManager().getPlugin("CarbonChat"); this.carbonChat = (CarbonChatBukkit) Bukkit.getPluginManager().getPlugin("CarbonChat");
} }
public BukkitChatUser(@NonNull final UUID uuid) { public BukkitChatUser(final @NonNull UUID uuid) {
this(); this();
this.uuid = uuid; this.uuid = uuid;
} }
@@ -63,7 +68,12 @@ public class BukkitChatUser implements ChatUser, ForwardingAudience {
@Override @Override
@NonNull @NonNull
public Iterable<@NonNull ? extends Audience> audiences() { public Iterable<@NonNull ? extends Audience> audiences() {
return Collections.singleton(this.carbonChat.messageProcessor().audiences().player(this.uuid)); return Collections.singleton(this);
}
@Override
public boolean online() {
return Bukkit.getPlayer(this.uuid()) != null;
} }
@Override @Override
@@ -84,7 +94,7 @@ public class BukkitChatUser implements ChatUser, ForwardingAudience {
} }
@Override @Override
public boolean hasPermission(@NonNull final String permission) { public boolean hasPermission(final @NonNull String permission) {
return LuckPermsProvider.get().getUserManager().getUser(this.uuid()) return LuckPermsProvider.get().getUserManager().getUser(this.uuid())
.getCachedData().getPermissionData().checkPermission(permission).asBoolean(); .getCachedData().getPermissionData().checkPermission(permission).asBoolean();
} }
@@ -156,7 +166,7 @@ public class BukkitChatUser implements ChatUser, ForwardingAudience {
} }
@Override @Override
public void selectedChannel(@NonNull final ChatChannel chatChannel, final boolean fromRemote) { public void selectedChannel(final @NonNull ChatChannel chatChannel, final boolean fromRemote) {
final String failureMessage = chatChannel.switchFailureMessage(); final String failureMessage = chatChannel.switchFailureMessage();
final ChannelSwitchEvent event = new ChannelSwitchEvent(chatChannel, this, failureMessage); final ChannelSwitchEvent event = new ChannelSwitchEvent(chatChannel, this, failureMessage);
@@ -194,12 +204,12 @@ public class BukkitChatUser implements ChatUser, ForwardingAudience {
} }
@Override @Override
public boolean ignoringUser(@NonNull final UUID uuid) { public boolean ignoringUser(final @NonNull UUID uuid) {
return this.ignoredUsers.contains(uuid); return this.ignoredUsers.contains(uuid);
} }
@Override @Override
public void ignoringUser(@NonNull final UUID uuid, final boolean ignoring, final boolean fromRemote) { public void ignoringUser(final @NonNull UUID uuid, final boolean ignoring, final boolean fromRemote) {
if (ignoring) { if (ignoring) {
this.ignoredUsers.add(uuid); this.ignoredUsers.add(uuid);
} else { } else {
@@ -215,11 +225,50 @@ public class BukkitChatUser implements ChatUser, ForwardingAudience {
} }
} }
@Override
@NonNull @NonNull
public List<@NonNull UUID> ignoredUsers() { public Iterable<@NonNull UUID> ignoredUsers() {
return this.ignoredUsers; return this.ignoredUsers;
} }
LuckPerms luckPerms = LuckPermsProvider.get();
@Override
public boolean hasGroup(final @NonNull String groupName) {
return this.hasGroup(this.luckPerms.getGroupManager().getGroup(groupName));
}
@Override
public boolean hasGroup(final @NonNull Group group) {
return this.groups().contains(group);
}
@Override
public @NonNull Collection<@NonNull Group> groups() {
final User user = this.luckPerms.getUserManager().getUser(this.uuid());
return user.getInheritedGroups(QueryOptions.nonContextual());
}
@Override
public @Nullable Group primaryGroup() {
final User user = this.luckPerms.getUserManager().getUser(this.uuid());
return this.luckPerms.getGroupManager().getGroup(user.getPrimaryGroup());
}
@Override
@NonNull
public Iterable<@NonNull ChatUser> ignoredChatUsers() {
final List<ChatUser> users = new ArrayList<>();
for (final UUID uuid : this.ignoredUsers) {
users.add(this.carbonChat.userService().wrap(uuid));
}
return users;
}
@Override @Override
public void muted(final boolean muted, final boolean fromRemote) { public void muted(final boolean muted, final boolean fromRemote) {
this.muted = muted; this.muted = muted;
@@ -272,7 +321,7 @@ public class BukkitChatUser implements ChatUser, ForwardingAudience {
@Override @Override
@NonNull @NonNull
public UserChannelSettings channelSettings(@NonNull final ChatChannel channel) { public UserChannelSettings channelSettings(final @NonNull ChatChannel channel) {
return this.channelSettings.computeIfAbsent(channel.key(), name -> { return this.channelSettings.computeIfAbsent(channel.key(), name -> {
return new SimpleUserChannelSettings(this.uuid, channel.key()); return new SimpleUserChannelSettings(this.uuid, channel.key());
}); });
@@ -300,7 +349,7 @@ public class BukkitChatUser implements ChatUser, ForwardingAudience {
} }
@Override @Override
public void sendMessage(@NonNull final ChatUser sender, @NonNull final String message) { public void sendMessage(final @NonNull ChatUser sender, final @NonNull String message) {
if (this.ignoringUser(sender) || sender.ignoringUser(this)) { if (this.ignoringUser(sender) || sender.ignoringUser(this)) {
return; return;
} }
@@ -24,7 +24,7 @@ public class SimpleUserChannelSettings implements UserChannelSettings {
@MonotonicNonNull // @NonNull but not initialised in all constructors. @MonotonicNonNull // @NonNull but not initialised in all constructors.
private String channel; private String channel;
public SimpleUserChannelSettings(@NonNull final UUID uuid, @NonNull final String channel) { public SimpleUserChannelSettings(final @NonNull UUID uuid, final @NonNull String channel) {
this.uuid = uuid; this.uuid = uuid;
this.channel = channel; this.channel = channel;
} }
@@ -44,7 +44,7 @@ public class SimpleUserChannelSettings implements UserChannelSettings {
this.spying = spying; this.spying = spying;
if (!fromRemote) { if (!fromRemote) {
this.carbonChat.messageManager().sendMessage("spying-channel", this.uuid, byteArray -> { this.carbonChat.messageService().sendMessage("spying-channel", this.uuid, byteArray -> {
byteArray.writeUTF(this.channel); byteArray.writeUTF(this.channel);
byteArray.writeBoolean(spying); byteArray.writeBoolean(spying);
}); });
@@ -61,7 +61,7 @@ public class SimpleUserChannelSettings implements UserChannelSettings {
this.ignored = ignored; this.ignored = ignored;
if (!fromRemote) { if (!fromRemote) {
this.carbonChat.messageManager().sendMessage("ignoring-channel", this.uuid, byteArray -> { this.carbonChat.messageService().sendMessage("ignoring-channel", this.uuid, byteArray -> {
byteArray.writeUTF(this.channel); byteArray.writeUTF(this.channel);
byteArray.writeBoolean(ignored); byteArray.writeBoolean(ignored);
}); });
@@ -87,7 +87,7 @@ public class SimpleUserChannelSettings implements UserChannelSettings {
} }
if (!fromRemote) { if (!fromRemote) {
this.carbonChat.messageManager().sendMessage("channel-color", this.uuid, byteArray -> { this.carbonChat.messageService().sendMessage("channel-color", this.uuid, byteArray -> {
byteArray.writeUTF(color.asHexString()); byteArray.writeUTF(color.asHexString());
}); });
} }
@@ -13,7 +13,7 @@ public class CarbonPlaceholders extends PlaceholderExpansion {
@NonNull @NonNull
private final CarbonChatBukkit carbonChat; private final CarbonChatBukkit carbonChat;
public CarbonPlaceholders(@NonNull final CarbonChatBukkit carbonChat) { public CarbonPlaceholders(final @NonNull CarbonChatBukkit carbonChat) {
this.carbonChat = carbonChat; this.carbonChat = carbonChat;
} }
@@ -42,7 +42,7 @@ public class CarbonPlaceholders extends PlaceholderExpansion {
@Override @Override
@Nullable @Nullable
public String onPlaceholderRequest(@NonNull final Player player, @NonNull final String identifier) { public String onPlaceholderRequest(final @NonNull Player player, final @NonNull String identifier) {
final String key = identifier.toLowerCase(); final String key = identifier.toLowerCase();
if (key.startsWith("can_use_")) { if (key.startsWith("can_use_")) {
@@ -66,7 +66,7 @@ public final class CarbonUtils {
} }
@NonNull @NonNull
public static Component createComponent(@NonNull final Player player) { public static Component createComponent(final @NonNull Player player) {
if (!FunctionalityConstants.HAS_HOVER_EVENT_METHOD) { if (!FunctionalityConstants.HAS_HOVER_EVENT_METHOD) {
return net.kyori.adventure.text.TextComponent.empty(); return net.kyori.adventure.text.TextComponent.empty();
} }
@@ -10,7 +10,7 @@ public final class CommandUtils {
} }
public static void handleDuplicateCommands(@NonNull final CommandSettings settings) { public static void handleDuplicateCommands(final @NonNull CommandSettings settings) {
CommandAPI.unregister(settings.name()); CommandAPI.unregister(settings.name());
for (final String command : settings.aliases()) { for (final String command : settings.aliases()) {
@@ -29,7 +29,7 @@ public final class FunctionalityConstants {
} }
private static boolean noThrow(@NonNull final ThrowingRunnable runnable) { private static boolean noThrow(final @NonNull ThrowingRunnable runnable) {
try { try {
runnable.run(); runnable.run();
return true; return true;
+5
View File
@@ -12,4 +12,9 @@ dependencies {
compileOnly 'com.google.code.gson:gson:2.8.0' compileOnly 'com.google.code.gson:gson:2.8.0'
compile 'org.spongepowered:configurate-yaml:4.0.0-SNAPSHOT' compile 'org.spongepowered:configurate-yaml:4.0.0-SNAPSHOT'
compile 'co.aikar:idb-core:1.0.0-SNAPSHOT'
compile 'com.zaxxer:HikariCP:2.4.1'
compileOnly 'org.slf4j:slf4j-api:1.7.25'
} }
@@ -17,13 +17,13 @@ public class AdventureManager implements MessageProcessor {
@NonNull @NonNull
private final FormatType formatType; private final FormatType formatType;
public AdventureManager(@NonNull final AudienceProvider provider, @NonNull final FormatType formatType) { public AdventureManager(final @NonNull AudienceProvider provider, final @NonNull FormatType formatType) {
this.provider = provider; this.provider = provider;
this.formatType = formatType; this.formatType = formatType;
} }
@Override @Override
public @NonNull Component processMessage(@Nullable final String input, @NonNull final String @NonNull ... placeholders) { public @NonNull Component processMessage(@Nullable final String input, final @NonNull String @NonNull ... placeholders) {
if (input == null || input.trim().isEmpty()) { if (input == null || input.trim().isEmpty()) {
return TextComponent.empty(); return TextComponent.empty();
} }
@@ -41,7 +41,7 @@ public class AdventureManager implements MessageProcessor {
} }
} }
private @NonNull Component processMojang(@NonNull String input, @NonNull final String @NonNull ... placeholders) { private @NonNull Component processMojang(@NonNull String input, final @NonNull String @NonNull ... placeholders) {
for (int i = 0; i < placeholders.length; i += 2) { for (int i = 0; i < placeholders.length; i += 2) {
final String placeholder = placeholders[i]; final String placeholder = placeholders[i];
final String replacement = placeholders[i + 1]; final String replacement = placeholders[i + 1];
@@ -0,0 +1,106 @@
package net.draycia.carbon.common.channels;
import net.draycia.carbon.api.Context;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
public class ChannelSettings {
@Nullable
public String color() {
}
@Nullable
public Map<String, Context> contexts() {
}
@Nullable
public Map<String, String> formats() {
}
@Nullable
public String defaultFormatName() {
}
public boolean isDefault() {
}
public boolean ignorable() {
}
public boolean crossServer() {
}
public boolean honorsRecipientList() {
}
public boolean permissionGroupMatching() {
}
@NonNull
public List<@NonNull String> groupOverrides() {
}
@NonNull
public String name() {
}
@Nullable
public String messagePrefix() {
}
@Nullable
public String switchMessage() {
}
@Nullable
public String switchOtherMessage() {
}
@Nullable
public String switchFailureMessage() {
}
@Nullable
public String cannotIgnoreMessage() {
}
@Nullable
public String toggleOffMessage() {
}
@Nullable
public String toggleOnMessage() {
}
@Nullable
public String toggleOtherOnMessage() {
}
@Nullable
public String toggleOtherOffMessage() {
}
@Nullable
public String cannotUseMessage() {
}
public boolean primaryGroupOnly() {
}
public boolean shouldCancelChatEvent() {
}
@NonNull
public List<@NonNull Pattern> itemLinkPatterns() {
}
@Nullable
public String aliases() {
}
}
@@ -18,7 +18,7 @@ public class AliasedChannelCommand {
private final @NonNull String commandName; private final @NonNull String commandName;
public AliasedChannelCommand(@NonNull final CommandManager<ChatUser> commandManager, @NonNull final ChatChannel chatChannel) { public AliasedChannelCommand(final @NonNull CommandManager<ChatUser> commandManager, final @NonNull ChatChannel chatChannel) {
this.carbonChat = CarbonChatProvider.carbonChat(); this.carbonChat = CarbonChatProvider.carbonChat();
this.chatChannel = chatChannel; this.chatChannel = chatChannel;
this.commandName = chatChannel.key(); this.commandName = chatChannel.key();
@@ -41,7 +41,7 @@ public class AliasedChannelCommand {
); );
} }
private void channel(@NonNull final CommandContext<ChatUser> context) { private void channel(final @NonNull CommandContext<ChatUser> context) {
final ChatUser user = context.getSender(); final ChatUser user = context.getSender();
if (user.channelSettings(this.chatChannel()).ignored()) { if (user.channelSettings(this.chatChannel()).ignored()) {
@@ -56,7 +56,7 @@ public class AliasedChannelCommand {
user.selectedChannel(this.chatChannel()); user.selectedChannel(this.chatChannel());
} }
private void sendMessage(@NonNull final CommandContext<ChatUser> context) { private void sendMessage(final @NonNull CommandContext<ChatUser> context) {
context.<String>get("message").ifPresent(message -> { context.<String>get("message").ifPresent(message -> {
final Component component = this.chatChannel().sendMessage(context.getSender(), message, false); final Component component = this.chatChannel().sendMessage(context.getSender(), message, false);
@@ -47,7 +47,7 @@ public class ChannelCommand {
); );
} }
private void channel(@NonNull final CommandContext<ChatUser> context) { private void channel(final @NonNull CommandContext<ChatUser> context) {
final ChatUser user = context.getSender(); final ChatUser user = context.getSender();
final ChatChannel channel = context.getRequired("channel"); final ChatChannel channel = context.getRequired("channel");
@@ -63,7 +63,7 @@ public class ChannelCommand {
user.selectedChannel(channel); user.selectedChannel(channel);
} }
private void sendMessage(@NonNull final CommandContext<ChatUser> context) { private void sendMessage(final @NonNull CommandContext<ChatUser> context) {
final ChatUser user = context.getSender(); final ChatUser user = context.getSender();
final ChatChannel channel = context.getRequired("channel"); final ChatChannel channel = context.getRequired("channel");
final String message = context.getRequired("message"); final String message = context.getRequired("message");
@@ -22,7 +22,7 @@ public class ChannelListCommand {
@NonNull @NonNull
private final CarbonChat carbonChat; private final CarbonChat carbonChat;
public ChannelListCommand(@NonNull final CommandManager<ChatUser> commandManager) { public ChannelListCommand(final @NonNull CommandManager<ChatUser> commandManager) {
this.carbonChat = CarbonChatProvider.carbonChat(); this.carbonChat = CarbonChatProvider.carbonChat();
final CommandSettings commandSettings = this.carbonChat.commandSettingsRegistry().get("channellist"); final CommandSettings commandSettings = this.carbonChat.commandSettingsRegistry().get("channellist");
@@ -51,11 +51,11 @@ public class ChannelListCommand {
); );
} }
public void toggleSelf(@NonNull final CommandContext<ChatUser> context) { public void toggleSelf(final @NonNull CommandContext<ChatUser> context) {
this.listAndSend(context.getSender(), context.getSender(), this.carbonChat.channelRegistry().iterator()); this.listAndSend(context.getSender(), context.getSender(), this.carbonChat.channelRegistry().iterator());
} }
public void toggleOther(@NonNull final CommandContext<ChatUser> context) { public void toggleOther(final @NonNull CommandContext<ChatUser> context) {
final ChatUser sender = context.getSender(); final ChatUser sender = context.getSender();
final ChatUser user = context.getRequired("user"); final ChatUser user = context.getRequired("user");
@@ -69,8 +69,8 @@ public class ChannelListCommand {
this.listAndSend(sender, user, allChannels); this.listAndSend(sender, user, allChannels);
} }
private void listAndSend(@NonNull final ChatUser sender, @NonNull final ChatUser user, private void listAndSend(final @NonNull ChatUser sender, final @NonNull ChatUser user,
@NonNull final Iterator<ChatChannel> allChannels) { final @NonNull Iterator<ChatChannel> allChannels) {
ChatChannel channel; ChatChannel channel;
final List<ChatChannel> canSee = new ArrayList<>(); final List<ChatChannel> canSee = new ArrayList<>();
final List<ChatChannel> cannotSee = new ArrayList<>(); final List<ChatChannel> cannotSee = new ArrayList<>();
@@ -110,7 +110,7 @@ public class ChannelListCommand {
} }
} }
private void makeList(@NonNull final Iterator<@NonNull ChatChannel> iterator, final TextComponent.@NonNull Builder list) { private void makeList(final @NonNull Iterator<@NonNull ChatChannel> iterator, final TextComponent.@NonNull Builder list) {
final String listSeparator = this.carbonChat.translations().channelListSeparator(); final String listSeparator = this.carbonChat.translations().channelListSeparator();
// TODO: Larry, why did you double assign the listSeparatorComponent? // TODO: Larry, why did you double assign the listSeparatorComponent?
final Component listSeparatorComponent = TextComponent.of(listSeparator); final Component listSeparatorComponent = TextComponent.of(listSeparator);
@@ -14,7 +14,7 @@ public class ChatReloadCommand {
@NonNull @NonNull
private final CarbonChat carbonChat; private final CarbonChat carbonChat;
public ChatReloadCommand(@NonNull final CommandManager<ChatUser> commandManager) { public ChatReloadCommand(final @NonNull CommandManager<ChatUser> commandManager) {
this.carbonChat = CarbonChatProvider.carbonChat(); this.carbonChat = CarbonChatProvider.carbonChat();
final CommandSettings commandSettings = this.carbonChat.commandSettingsRegistry().get("chatreload"); final CommandSettings commandSettings = this.carbonChat.commandSettingsRegistry().get("chatreload");
@@ -33,7 +33,7 @@ public class ChatReloadCommand {
); );
} }
private void reloadConfig(@NonNull final CommandContext<ChatUser> context) { private void reloadConfig(final @NonNull CommandContext<ChatUser> context) {
this.carbonChat.reloadConfig(); this.carbonChat.reloadConfig();
final Component message = this.carbonChat.messageProcessor() final Component message = this.carbonChat.messageProcessor()
@@ -14,7 +14,7 @@ public class ClearChatCommand {
@NonNull @NonNull
private final CarbonChat carbonChat; private final CarbonChat carbonChat;
public ClearChatCommand(@NonNull final CommandManager<ChatUser> commandManager) { public ClearChatCommand(final @NonNull CommandManager<ChatUser> commandManager) {
this.carbonChat = CarbonChatProvider.carbonChat(); this.carbonChat = CarbonChatProvider.carbonChat();
final CommandSettings commandSettings = this.carbonChat.commandSettingsRegistry().get("clearchat"); final CommandSettings commandSettings = this.carbonChat.commandSettingsRegistry().get("clearchat");
@@ -33,7 +33,7 @@ public class ClearChatCommand {
); );
} }
private void clearChat(@NonNull final CommandContext<ChatUser> context) { private void clearChat(final @NonNull CommandContext<ChatUser> context) {
final String sender = context.getSender().name(); final String sender = context.getSender().name();
final String format = this.carbonChat.moderationSettings().clearChat().message(); final String format = this.carbonChat.moderationSettings().clearChat().message();
final Component component = this.carbonChat.messageProcessor().processMessage(format, "br", "\n"); final Component component = this.carbonChat.messageProcessor().processMessage(format, "br", "\n");
@@ -15,7 +15,7 @@ public class IgnoreCommand {
@NonNull @NonNull
private final CarbonChat carbonChat; private final CarbonChat carbonChat;
public IgnoreCommand(@NonNull final CommandManager<ChatUser> commandManager) { public IgnoreCommand(final @NonNull CommandManager<ChatUser> commandManager) {
this.carbonChat = CarbonChatProvider.carbonChat(); this.carbonChat = CarbonChatProvider.carbonChat();
final CommandSettings commandSettings = this.carbonChat.commandSettingsRegistry().get("ignore"); final CommandSettings commandSettings = this.carbonChat.commandSettingsRegistry().get("ignore");
@@ -35,7 +35,7 @@ public class IgnoreCommand {
); );
} }
private void ignoreUser(@NonNull final CommandContext<ChatUser> context) { private void ignoreUser(final @NonNull CommandContext<ChatUser> context) {
final ChatUser sender = context.getSender(); final ChatUser sender = context.getSender();
final ChatUser targetUser = context.getRequired("user"); final ChatUser targetUser = context.getRequired("user");
@@ -15,7 +15,7 @@ public class MeCommand {
@NonNull @NonNull
private final CarbonChat carbonChat; private final CarbonChat carbonChat;
public MeCommand(@NonNull final CommandManager<ChatUser> commandManager) { public MeCommand(final @NonNull CommandManager<ChatUser> commandManager) {
this.carbonChat = CarbonChatProvider.carbonChat(); this.carbonChat = CarbonChatProvider.carbonChat();
final CommandSettings commandSettings = this.carbonChat.commandSettingsRegistry().get("me"); final CommandSettings commandSettings = this.carbonChat.commandSettingsRegistry().get("me");
@@ -35,7 +35,7 @@ public class MeCommand {
); );
} }
private void message(@NonNull final CommandContext<ChatUser> context) { private void message(final @NonNull CommandContext<ChatUser> context) {
final ChatUser user = context.getSender(); final ChatUser user = context.getSender();
final String message = context.<String>getRequired("message").replace("</pre>", ""); final String message = context.<String>getRequired("message").replace("</pre>", "");
@@ -12,7 +12,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
public class MessageCommand { public class MessageCommand {
public MessageCommand(@NonNull final CommandManager<ChatUser> commandManager) { public MessageCommand(final @NonNull CommandManager<ChatUser> commandManager) {
final CarbonChat carbonChat = CarbonChatProvider.carbonChat(); final CarbonChat carbonChat = CarbonChatProvider.carbonChat();
final CommandSettings commandSettings = carbonChat.commandSettingsRegistry().get("message"); final CommandSettings commandSettings = carbonChat.commandSettingsRegistry().get("message");
@@ -32,7 +32,7 @@ public class MessageCommand {
); );
} }
private void sendMessage(@NonNull final CommandContext<ChatUser> context) { private void sendMessage(final @NonNull CommandContext<ChatUser> context) {
context.<ChatUser>getRequired("target") context.<ChatUser>getRequired("target")
.sendMessage(context.getSender(), context.getRequired("message")); .sendMessage(context.getSender(), context.getRequired("message"));
} }
@@ -15,7 +15,7 @@ public class MuteCommand {
@NonNull @NonNull
private final CarbonChat carbonChat; private final CarbonChat carbonChat;
public MuteCommand(@NonNull final CommandManager<ChatUser> commandManager) { public MuteCommand(final @NonNull CommandManager<ChatUser> commandManager) {
this.carbonChat = CarbonChatProvider.carbonChat(); this.carbonChat = CarbonChatProvider.carbonChat();
final CommandSettings commandSettings = this.carbonChat.commandSettingsRegistry().get("mute"); final CommandSettings commandSettings = this.carbonChat.commandSettingsRegistry().get("mute");
@@ -35,7 +35,7 @@ public class MuteCommand {
); );
} }
private void mute(@NonNull final CommandContext<ChatUser> context) { private void mute(final @NonNull CommandContext<ChatUser> context) {
final ChatUser user = context.getSender(); final ChatUser user = context.getSender();
final ChatUser target = context.getRequired("user"); final ChatUser target = context.getRequired("user");
@@ -15,7 +15,7 @@ public class NicknameCommand {
@NonNull @NonNull
private final CarbonChat carbonChat; private final CarbonChat carbonChat;
public NicknameCommand(@NonNull final CommandManager<ChatUser> commandManager) { public NicknameCommand(final @NonNull CommandManager<ChatUser> commandManager) {
this.carbonChat = CarbonChatProvider.carbonChat(); this.carbonChat = CarbonChatProvider.carbonChat();
final CommandSettings commandSettings = this.carbonChat.commandSettingsRegistry().get("nickname"); final CommandSettings commandSettings = this.carbonChat.commandSettingsRegistry().get("nickname");
@@ -47,7 +47,7 @@ public class NicknameCommand {
); );
} }
private void nicknameSelf(@NonNull final CommandContext<ChatUser> context) { private void nicknameSelf(final @NonNull CommandContext<ChatUser> context) {
final ChatUser user = context.getSender(); final ChatUser user = context.getSender();
String nickname = context.getRequired("nickname"); String nickname = context.getRequired("nickname");
@@ -70,7 +70,7 @@ public class NicknameCommand {
"user", user.name())); "user", user.name()));
} }
private void nicknameOther(@NonNull final CommandContext<ChatUser> context) { private void nicknameOther(final @NonNull CommandContext<ChatUser> context) {
final ChatUser target = context.getRequired("user"); final ChatUser target = context.getRequired("user");
String nickname = context.getRequired("nickname"); String nickname = context.getRequired("nickname");
@@ -15,7 +15,7 @@ public class ReplyCommand {
@NonNull @NonNull
private final CarbonChat carbonChat; private final CarbonChat carbonChat;
public ReplyCommand(@NonNull final CommandManager<ChatUser> commandManager) { public ReplyCommand(final @NonNull CommandManager<ChatUser> commandManager) {
this.carbonChat = CarbonChatProvider.carbonChat(); this.carbonChat = CarbonChatProvider.carbonChat();
final CommandSettings commandSettings = this.carbonChat.commandSettingsRegistry().get("reply"); final CommandSettings commandSettings = this.carbonChat.commandSettingsRegistry().get("reply");
@@ -35,7 +35,7 @@ public class ReplyCommand {
); );
} }
private void reply(@NonNull final CommandContext<ChatUser> context) { private void reply(final @NonNull CommandContext<ChatUser> context) {
final ChatUser user = context.getSender(); final ChatUser user = context.getSender();
final String input = context.getRequired("message"); final String input = context.getRequired("message");
@@ -15,7 +15,7 @@ public class SetColorCommand {
@NonNull @NonNull
private final CarbonChat carbonChat; private final CarbonChat carbonChat;
public SetColorCommand(@NonNull final CommandManager<ChatUser> commandManager) { public SetColorCommand(final @NonNull CommandManager<ChatUser> commandManager) {
this.carbonChat = CarbonChatProvider.carbonChat(); this.carbonChat = CarbonChatProvider.carbonChat();
final CommandSettings commandSettings = this.carbonChat.commandSettingsRegistry().get("setcolor"); final CommandSettings commandSettings = this.carbonChat.commandSettingsRegistry().get("setcolor");
@@ -15,7 +15,7 @@ public class ShadowMuteCommand {
@NonNull @NonNull
private final CarbonChat carbonChat; private final CarbonChat carbonChat;
public ShadowMuteCommand(@NonNull final CommandManager<ChatUser> commandManager) { public ShadowMuteCommand(final @NonNull CommandManager<ChatUser> commandManager) {
this.carbonChat = CarbonChatProvider.carbonChat(); this.carbonChat = CarbonChatProvider.carbonChat();
final CommandSettings commandSettings = this.carbonChat.commandSettingsRegistry().get("shadowmute"); final CommandSettings commandSettings = this.carbonChat.commandSettingsRegistry().get("shadowmute");
@@ -35,7 +35,7 @@ public class ShadowMuteCommand {
); );
} }
private void shadowMute(@NonNull final CommandContext<ChatUser> context) { private void shadowMute(final @NonNull CommandContext<ChatUser> context) {
final ChatUser user = context.getSender(); final ChatUser user = context.getSender();
final ChatUser target = context.getRequired("user"); final ChatUser target = context.getRequired("user");
@@ -18,7 +18,7 @@ public class SpyChannelCommand {
@NonNull @NonNull
private final CarbonChat carbonChat; private final CarbonChat carbonChat;
public SpyChannelCommand(@NonNull final CommandManager<ChatUser> commandManager) { public SpyChannelCommand(final @NonNull CommandManager<ChatUser> commandManager) {
this.carbonChat = CarbonChatProvider.carbonChat(); this.carbonChat = CarbonChatProvider.carbonChat();
final CommandSettings commandSettings = this.carbonChat.commandSettingsRegistry().get("spy"); final CommandSettings commandSettings = this.carbonChat.commandSettingsRegistry().get("spy");
@@ -59,7 +59,7 @@ public class SpyChannelCommand {
); );
} }
private void spyChannel(@NonNull final CommandContext<ChatUser> context) { private void spyChannel(final @NonNull CommandContext<ChatUser> context) {
final ChatUser user = context.getSender(); final ChatUser user = context.getSender();
final ChatChannel chatChannel = context.getRequired("channel"); final ChatChannel chatChannel = context.getRequired("channel");
@@ -79,7 +79,7 @@ public class SpyChannelCommand {
"color", "<color:" + chatChannel.channelColor(user).toString() + ">", "channel", chatChannel.name())); "color", "<color:" + chatChannel.channelColor(user).toString() + ">", "channel", chatChannel.name()));
} }
private void spyWhispers(@NonNull final CommandContext<ChatUser> context) { private void spyWhispers(final @NonNull CommandContext<ChatUser> context) {
final ChatUser user = context.getSender(); final ChatUser user = context.getSender();
final String message; final String message;
@@ -95,7 +95,7 @@ public class SpyChannelCommand {
user.sendMessage(this.carbonChat.messageProcessor().processMessage(message, "br", "\n")); user.sendMessage(this.carbonChat.messageProcessor().processMessage(message, "br", "\n"));
} }
private void spyEverything(@NonNull final CommandContext<ChatUser> context) { private void spyEverything(final @NonNull CommandContext<ChatUser> context) {
final ChatUser user = context.getSender(); final ChatUser user = context.getSender();
final Boolean shouldSpy = context.getRequired("enabled"); final Boolean shouldSpy = context.getRequired("enabled");
@@ -17,7 +17,7 @@ public class SudoChannelCommand {
@NonNull @NonNull
private final CarbonChat carbonChat; private final CarbonChat carbonChat;
public SudoChannelCommand(@NonNull final CommandManager<ChatUser> commandManager) { public SudoChannelCommand(final @NonNull CommandManager<ChatUser> commandManager) {
this.carbonChat = CarbonChatProvider.carbonChat(); this.carbonChat = CarbonChatProvider.carbonChat();
final CommandSettings commandSettings = this.carbonChat.commandSettingsRegistry().get("sudochannel"); final CommandSettings commandSettings = this.carbonChat.commandSettingsRegistry().get("sudochannel");
@@ -50,7 +50,7 @@ public class SudoChannelCommand {
); );
} }
private void otherChannel(@NonNull final CommandContext<ChatUser> context) { private void otherChannel(final @NonNull CommandContext<ChatUser> context) {
final ChatUser sender = context.getSender(); final ChatUser sender = context.getSender();
final ChatUser user = context.getRequired("user"); final ChatUser user = context.getRequired("user");
final ChatChannel channel = context.getRequired("channel"); final ChatChannel channel = context.getRequired("channel");
@@ -69,7 +69,7 @@ public class SudoChannelCommand {
"player", user.name())); "player", user.name()));
} }
private void sendMessageOther(@NonNull final CommandContext<ChatUser> context) { private void sendMessageOther(final @NonNull CommandContext<ChatUser> context) {
final ChatUser user = context.getRequired("user"); final ChatUser user = context.getRequired("user");
final ChatChannel channel = context.getRequired("channel"); final ChatChannel channel = context.getRequired("channel");
final String message = context.getRequired("message"); final String message = context.getRequired("message");
@@ -16,7 +16,7 @@ public class ToggleCommand {
@NonNull @NonNull
private final CarbonChat carbonChat; private final CarbonChat carbonChat;
public ToggleCommand(@NonNull final CommandManager<ChatUser> commandManager) { public ToggleCommand(final @NonNull CommandManager<ChatUser> commandManager) {
this.carbonChat = CarbonChatProvider.carbonChat(); this.carbonChat = CarbonChatProvider.carbonChat();
final CommandSettings commandSettings = this.carbonChat.commandSettingsRegistry().get("toggle"); final CommandSettings commandSettings = this.carbonChat.commandSettingsRegistry().get("toggle");
@@ -47,7 +47,7 @@ public class ToggleCommand {
); );
} }
private void toggleSelf(@NonNull final CommandContext<ChatUser> context) { private void toggleSelf(final @NonNull CommandContext<ChatUser> context) {
final ChatUser user = context.getSender(); final ChatUser user = context.getSender();
final ChatChannel channel = context.getRequired("channel"); final ChatChannel channel = context.getRequired("channel");
@@ -69,7 +69,7 @@ public class ToggleCommand {
"color", "<color:" + channel.channelColor(user).toString() + ">", "channel", channel.name())); "color", "<color:" + channel.channelColor(user).toString() + ">", "channel", channel.name()));
} }
private void toggleOther(@NonNull final CommandContext<ChatUser> context) { private void toggleOther(final @NonNull CommandContext<ChatUser> context) {
final ChatUser sender = context.getSender(); final ChatUser sender = context.getSender();
final ChatUser user = context.getRequired("user"); final ChatUser user = context.getRequired("user");
final ChatChannel channel = context.getRequired("channel"); final ChatChannel channel = context.getRequired("channel");
@@ -13,22 +13,22 @@ import java.util.function.Consumer;
public class EmptyMessageService implements MessageService { public class EmptyMessageService implements MessageService {
@Override @Override
public void registerUserMessageListener(@NonNull final String key, @NonNull final BiConsumer<@NonNull ChatUser, @NonNull ByteArrayDataInput> listener) { public void registerUserMessageListener(final @NonNull String key, final @NonNull BiConsumer<@NonNull ChatUser, @NonNull ByteArrayDataInput> listener) {
// do nothing // do nothing
} }
@Override @Override
public void registerUUIDMessageListener(@NonNull final String key, @NonNull final BiConsumer<@NonNull UUID, @NonNull ByteArrayDataInput> listener) { public void registerUUIDMessageListener(final @NonNull String key, final @NonNull BiConsumer<@NonNull UUID, @NonNull ByteArrayDataInput> listener) {
// do nothing // do nothing
} }
@Override @Override
public void unregisterMessageListener(@NonNull final String key) { public void unregisterMessageListener(final @NonNull String key) {
// do nothing // do nothing
} }
@Override @Override
public void sendMessage(@NonNull final String key, @NonNull final UUID uuid, @NonNull final Consumer<@NonNull ByteArrayDataOutput> consumer) { public void sendMessage(final @NonNull String key, final @NonNull UUID uuid, final @NonNull Consumer<@NonNull ByteArrayDataOutput> consumer) {
// do nothing // do nothing
} }
@@ -24,7 +24,7 @@ public class MessageManager {
@NonNull @NonNull
private final GsonComponentSerializer gsonSerializer; private final GsonComponentSerializer gsonSerializer;
public MessageManager(final @NonNull CarbonChat carbonChat, @NonNull final MessageService messageService) { public MessageManager(final @NonNull CarbonChat carbonChat, final @NonNull MessageService messageService) {
this.carbonChat = carbonChat; this.carbonChat = carbonChat;
this.messageService = messageService; this.messageService = messageService;
this.gsonSerializer = this.carbonChat.messageProcessor().audiences().gsonSerializer(); this.gsonSerializer = this.carbonChat.messageProcessor().audiences().gsonSerializer();
@@ -123,8 +123,8 @@ public class MessageManager {
return this.messageService; return this.messageService;
} }
public void sendMessage(@NonNull final String key, @NonNull final UUID uuid, public void sendMessage(final @NonNull String key, final @NonNull UUID uuid,
@NonNull final Consumer<@NonNull ByteArrayDataOutput> consumer) { final @NonNull Consumer<@NonNull ByteArrayDataOutput> consumer) {
this.messageService().sendMessage(key, uuid, consumer); this.messageService().sendMessage(key, uuid, consumer);
} }
@@ -10,23 +10,23 @@ public interface RedisListener extends RedisPubSubListener<String, String> {
void message(@NonNull String channel, @NonNull String message); void message(@NonNull String channel, @NonNull String message);
@Override @Override
default void message(@NonNull final String pattern, @NonNull final String channel, @NonNull final String message) { default void message(final @NonNull String pattern, final @NonNull String channel, final @NonNull String message) {
} }
@Override @Override
default void subscribed(@NonNull final String channel, final long count) { default void subscribed(final @NonNull String channel, final long count) {
} }
@Override @Override
default void psubscribed(@NonNull final String pattern, final long count) { default void psubscribed(final @NonNull String pattern, final long count) {
} }
@Override @Override
default void unsubscribed(@NonNull final String channel, final long count) { default void unsubscribed(final @NonNull String channel, final long count) {
} }
@Override @Override
default void punsubscribed(@NonNull final String pattern, final long count) { default void punsubscribed(final @NonNull String pattern, final long count) {
} }
} }
@@ -10,6 +10,7 @@ import io.lettuce.core.pubsub.api.sync.RedisPubSubCommands;
import net.draycia.carbon.api.CarbonChat; import net.draycia.carbon.api.CarbonChat;
import net.draycia.carbon.api.messaging.MessageService; import net.draycia.carbon.api.messaging.MessageService;
import net.draycia.carbon.api.users.ChatUser; import net.draycia.carbon.api.users.ChatUser;
import net.draycia.carbon.common.utils.RedisCredentials;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.Base64; import java.util.Base64;
@@ -39,7 +40,7 @@ public class RedisMessageService implements MessageService {
@NonNull @NonNull
private final CarbonChat carbonChat; private final CarbonChat carbonChat;
public RedisMessageService(@NonNull final CarbonChat carbonChat, @NonNull final RedisCredentials credentials) { public RedisMessageService(final @NonNull CarbonChat carbonChat, final @NonNull RedisCredentials credentials) {
this.carbonChat = carbonChat; this.carbonChat = carbonChat;
final RedisURI.Builder builder = RedisURI.Builder.redis(credentials.host(), credentials.port()) final RedisURI.Builder builder = RedisURI.Builder.redis(credentials.host(), credentials.port())
@@ -72,7 +73,7 @@ public class RedisMessageService implements MessageService {
}); });
} }
private void receiveMessage(@NonNull final UUID uuid, @NonNull final String key, @NonNull final ByteArrayDataInput value) { private void receiveMessage(final @NonNull UUID uuid, final @NonNull String key, final @NonNull ByteArrayDataInput value) {
final ChatUser user = this.carbonChat.userService().wrapIfLoaded(uuid); final ChatUser user = this.carbonChat.userService().wrapIfLoaded(uuid);
if (user != null) { if (user != null) {
@@ -91,19 +92,19 @@ public class RedisMessageService implements MessageService {
} }
@Override @Override
public void registerUserMessageListener(@NonNull final String key, @NonNull final BiConsumer<@NonNull ChatUser, @NonNull ByteArrayDataInput> listener) { public void registerUserMessageListener(final @NonNull String key, final @NonNull BiConsumer<@NonNull ChatUser, @NonNull ByteArrayDataInput> listener) {
this.userLoadedListeners.put(key, listener); this.userLoadedListeners.put(key, listener);
this.subscribeSync.subscribe(key); this.subscribeSync.subscribe(key);
} }
@Override @Override
public void registerUUIDMessageListener(@NonNull final String key, @NonNull final BiConsumer<@NonNull UUID, @NonNull ByteArrayDataInput> listener) { public void registerUUIDMessageListener(final @NonNull String key, final @NonNull BiConsumer<@NonNull UUID, @NonNull ByteArrayDataInput> listener) {
this.userNotLoadedListeners.put(key, listener); this.userNotLoadedListeners.put(key, listener);
this.subscribeSync.subscribe(key); this.subscribeSync.subscribe(key);
} }
@Override @Override
public void unregisterMessageListener(@NonNull final String key) { public void unregisterMessageListener(final @NonNull String key) {
this.userLoadedListeners.remove(key); this.userLoadedListeners.remove(key);
this.userNotLoadedListeners.remove(key); this.userNotLoadedListeners.remove(key);
@@ -111,7 +112,7 @@ public class RedisMessageService implements MessageService {
} }
@Override @Override
public void sendMessage(@NonNull final String key, @NonNull final UUID uuid, @NonNull final Consumer<@NonNull ByteArrayDataOutput> consumer) { public void sendMessage(final @NonNull String key, final @NonNull UUID uuid, final @NonNull Consumer<@NonNull ByteArrayDataOutput> consumer) {
final ByteArrayDataOutput msg = ByteStreams.newDataOutput(); final ByteArrayDataOutput msg = ByteStreams.newDataOutput();
msg.writeLong(this.serverUUID.getMostSignificantBits()); msg.writeLong(this.serverUUID.getMostSignificantBits());
@@ -32,13 +32,14 @@ public class JSONUserService<T extends ChatUser> implements UserService<T> {
private final @NonNull Gson gson = new GsonBuilder().setPrettyPrinting().create(); private final @NonNull Gson gson = new GsonBuilder().setPrettyPrinting().create();
private final @NonNull Type userType; private final @NonNull Type userType;
private final @NonNull Supplier<@NonNull Iterable<@NonNull T>> supplier; private final @NonNull Supplier<@NonNull Iterable<@NonNull T>> supplier;
private final @NonNull LoadingCache<@NonNull UUID, @NonNull T> userCache = CacheBuilder.newBuilder() private final @NonNull LoadingCache<@NonNull UUID, @NonNull T> userCache = CacheBuilder.newBuilder()
.removalListener(this::saveUser) .removalListener(this::saveUser)
.build(CacheLoader.from(this::loadUser)); .build(CacheLoader.from(this::loadUser));
public JSONUserService(@NonNull final Class<? extends ChatUser> userType, public JSONUserService(final @NonNull Class<? extends ChatUser> userType,
@NonNull final CarbonChat carbonChat, final @NonNull CarbonChat carbonChat,
@NonNull final Supplier<@NonNull Iterable<@NonNull T>> supplier) { final @NonNull Supplier<@NonNull Iterable<@NonNull T>> supplier) {
this.userType = userType; this.userType = userType;
this.carbonChat = carbonChat; this.carbonChat = carbonChat;
this.supplier = supplier; this.supplier = supplier;
@@ -61,7 +62,7 @@ public class JSONUserService<T extends ChatUser> implements UserService<T> {
@Override @Override
@Nullable @Nullable
public T wrap(@NonNull final UUID uuid) { public T wrap(final @NonNull UUID uuid) {
try { try {
return this.userCache.get(uuid); return this.userCache.get(uuid);
} catch (final ExecutionException exception) { } catch (final ExecutionException exception) {
@@ -72,25 +73,25 @@ public class JSONUserService<T extends ChatUser> implements UserService<T> {
@Override @Override
@Nullable @Nullable
public T wrapIfLoaded(@NonNull final UUID uuid) { public T wrapIfLoaded(final @NonNull UUID uuid) {
return this.userCache.getIfPresent(uuid); return this.userCache.getIfPresent(uuid);
} }
@Override @Override
@Nullable @Nullable
public T refreshUser(@NonNull final UUID uuid) { public T refreshUser(final @NonNull UUID uuid) {
this.userCache.invalidate(uuid); this.userCache.invalidate(uuid);
return this.wrap(uuid); return this.wrap(uuid);
} }
@Override @Override
public void invalidate(@NonNull final T user) { public void invalidate(final @NonNull T user) {
this.userCache.invalidate(user.uuid()); this.userCache.invalidate(user.uuid());
} }
@Override @Override
public void validate(@NonNull final T user) { public void validate(final @NonNull T user) {
this.userCache.put(user.uuid(), user); this.userCache.put(user.uuid(), user);
} }
@@ -100,7 +101,7 @@ public class JSONUserService<T extends ChatUser> implements UserService<T> {
} }
@Nullable @Nullable
private T loadUser(@NonNull final UUID uuid) { private T loadUser(final @NonNull UUID uuid) {
final File userFile = new File(this.carbonChat.dataFolder().toFile(), "users/" + uuid.toString() + ".json"); final File userFile = new File(this.carbonChat.dataFolder().toFile(), "users/" + uuid.toString() + ".json");
this.ensureFileExists(userFile); this.ensureFileExists(userFile);
@@ -123,7 +124,7 @@ public class JSONUserService<T extends ChatUser> implements UserService<T> {
return null; return null;
} }
private void saveUser(@NonNull final RemovalNotification<@NonNull UUID, @NonNull T> notification) { private void saveUser(final @NonNull RemovalNotification<@NonNull UUID, @NonNull T> notification) {
final File userFile = new File(this.carbonChat.dataFolder().toFile(), "users/" + notification.getKey().toString() + ".json"); final File userFile = new File(this.carbonChat.dataFolder().toFile(), "users/" + notification.getKey().toString() + ".json");
this.ensureFileExists(userFile); this.ensureFileExists(userFile);
@@ -134,7 +135,7 @@ public class JSONUserService<T extends ChatUser> implements UserService<T> {
} }
} }
private void ensureFileExists(@NonNull final File file) { private void ensureFileExists(final @NonNull File file) {
if (!file.getParentFile().exists()) { if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs(); file.getParentFile().mkdirs();
} }
@@ -1,58 +1,65 @@
package net.draycia.carbon.storage.impl; package net.draycia.carbon.common.users;
import co.aikar.idb.DatabaseOptions;
import co.aikar.idb.PooledDatabaseOptions;
import net.draycia.carbon.api.CarbonChat; import net.draycia.carbon.api.CarbonChat;
import net.draycia.carbon.api.channels.ChatChannel; import net.draycia.carbon.api.channels.ChatChannel;
import net.draycia.carbon.api.users.UserChannelSettings; import net.draycia.carbon.api.users.UserChannelSettings;
import co.aikar.idb.BukkitDB;
import co.aikar.idb.DB; import co.aikar.idb.DB;
import co.aikar.idb.Database; import co.aikar.idb.Database;
import co.aikar.idb.DbRow; import co.aikar.idb.DbRow;
import co.aikar.idb.DbStatement; import co.aikar.idb.DbStatement;
import co.aikar.idb.HikariPooledDatabase;
import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader; import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache; import com.google.common.cache.LoadingCache;
import com.google.common.cache.RemovalNotification; import com.google.common.cache.RemovalNotification;
import net.draycia.carbon.api.users.ChatUser; import net.draycia.carbon.api.users.ChatUser;
import net.draycia.carbon.api.users.UserService; import net.draycia.carbon.api.users.UserService;
import net.draycia.carbon.common.utils.SQLCredentials;
import net.kyori.adventure.text.format.TextColor; import net.kyori.adventure.text.format.TextColor;
import org.bukkit.configuration.ConfigurationSection;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Type;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.SQLSyntaxErrorException; import java.sql.SQLSyntaxErrorException;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.function.Supplier;
public class MySQLUserService implements UserService { public class MySQLUserService<T extends ChatUser> implements UserService<T> {
@NonNull private final @NonNull CarbonChat carbonChat;
private final CarbonChat carbonChat; private final @NonNull Database database;
@NonNull private final @NonNull Type userType;
private final Database database; private final @NonNull Supplier<@NonNull Iterable<@NonNull T>> supplier;
@NonNull
private final LoadingCache<@NonNull UUID, @NonNull BukkitChatUser> userCache = CacheBuilder.newBuilder() private final @NonNull LoadingCache<@NonNull UUID, @NonNull T> userCache = CacheBuilder.newBuilder()
.removalListener(this::saveUser) .removalListener(this::saveUser)
.build(CacheLoader.from(this::loadUser)); .build(CacheLoader.from(this::loadUser));
public MySQLUserService(@NonNull final CarbonChat carbonChat) { public MySQLUserService(final @NonNull CarbonChat carbonChat, final @NonNull SQLCredentials credentials,
final @NonNull Supplier<@NonNull Iterable<@NonNull T>> supplier,
final @NonNull Class<? extends ChatUser> userType) {
this.carbonChat = carbonChat; this.carbonChat = carbonChat;
this.userType = userType;
this.supplier = supplier;
final ConfigurationSection section = this.carbonChat.getConfig().getConfigurationSection("storage"); final String username = credentials.username();
final String password = credentials.password();
final String database = credentials.password();
final String host = credentials.host();
final int port = credentials.port();
if (section == null) { final String hostAndPort = host + ":" + port;
throw new IllegalStateException("Missing Database Credentials!");
}
final String username = section.getString("username", "username"); final DatabaseOptions options = DatabaseOptions.builder().mysql(username, password, database, hostAndPort).build();
final String password = section.getString("password", "password"); this.database = PooledDatabaseOptions.builder().options(options).createHikariDatabase();
final String dbname = section.getString("database", "0");
final String hostandport = section.getString("hostname", "hostname") + ":" + section.getString("port", "0");
this.database = new HikariPooledDatabase(BukkitDB.getRecommendedOptions(carbonChat, username, password, dbname, hostandport));
DB.setGlobalDatabase(this.database); DB.setGlobalDatabase(this.database);
@@ -74,6 +81,15 @@ public class MySQLUserService implements UserService {
} catch (final SQLException exception) { } catch (final SQLException exception) {
exception.printStackTrace(); exception.printStackTrace();
} }
final TimerTask timerTask = new TimerTask() {
@Override
public void run() {
MySQLUserService.this.userCache.cleanUp();
}
};
new Timer().schedule(timerTask, 0L, 300000L);
} }
@Override @Override
@@ -85,7 +101,7 @@ public class MySQLUserService implements UserService {
@Override @Override
@Nullable @Nullable
public ChatUser wrap(@NonNull final UUID uuid) { public T wrap(final @NonNull UUID uuid) {
try { try {
return this.userCache.get(uuid); return this.userCache.get(uuid);
} catch (final ExecutionException exception) { } catch (final ExecutionException exception) {
@@ -96,31 +112,42 @@ public class MySQLUserService implements UserService {
@Override @Override
@Nullable @Nullable
public ChatUser wrapIfLoaded(@NonNull final UUID uuid) { public T wrapIfLoaded(final @NonNull UUID uuid) {
return this.userCache.getIfPresent(uuid); return this.userCache.getIfPresent(uuid);
} }
@Override @Override
@Nullable @Nullable
public ChatUser refreshUser(@NonNull final UUID uuid) { public T refreshUser(final @NonNull UUID uuid) {
this.userCache.invalidate(uuid); this.userCache.invalidate(uuid);
return this.wrap(uuid); return this.wrap(uuid);
} }
@Override @Override
public void invalidate(@NonNull final ChatUser user) { public void invalidate(final @NonNull T user) {
this.userCache.invalidate(user.uuid()); this.userCache.invalidate(user.uuid());
} }
@Override @Override
public void validate(@NonNull final ChatUser user) { public void validate(final @NonNull T user) {
this.userCache.put(user.uuid(), (BukkitChatUser) user); this.userCache.put(user.uuid(), user);
} }
@NonNull @Override
private BukkitChatUser loadUser(@NonNull final UUID uuid) { public @NonNull Iterable<@NonNull T> onlineUsers() {
final BukkitChatUser user = new BukkitChatUser(uuid); return this.supplier.get();
}
private @Nullable T loadUser(final @NonNull UUID uuid) {
final T user;
try {
user = (T) this.userType.getClass().getDeclaredConstructor(UUID.class).newInstance(uuid);
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
e.printStackTrace();
return null;
}
try (final DbStatement statement = this.database.query("SELECT * from sc_users WHERE uuid = ?;")) { try (final DbStatement statement = this.database.query("SELECT * from sc_users WHERE uuid = ?;")) {
statement.execute(uuid.toString()); statement.execute(uuid.toString());
@@ -177,8 +204,8 @@ public class MySQLUserService implements UserService {
return user; return user;
} }
private void saveUser(@NonNull final RemovalNotification<@NonNull UUID, @NonNull BukkitChatUser> notification) { private void saveUser(final @NonNull RemovalNotification<@NonNull UUID, @NonNull T> notification) {
final BukkitChatUser user = notification.getValue(); final T user = notification.getValue();
this.database.createTransaction(stm -> { this.database.createTransaction(stm -> {
// Save user general data // Save user general data
@@ -188,13 +215,13 @@ public class MySQLUserService implements UserService {
selectedName = user.selectedChannel().key(); selectedName = user.selectedChannel().key();
} }
this.carbonChat.getLogger().info("Saving user data!"); this.carbonChat.logger().info("Saving user data!");
stm.executeUpdateQuery("INSERT INTO sc_users (uuid, channel, muted, shadowmuted, spyingwhispers, nickname) VALUES (?, ?, ?, ?, ?, ?) " + stm.executeUpdateQuery("INSERT INTO sc_users (uuid, channel, muted, shadowmuted, spyingwhispers, nickname) VALUES (?, ?, ?, ?, ?, ?) " +
"ON DUPLICATE KEY UPDATE channel = ?, muted = ?, shadowmuted = ?, spyingwhispers = ?, nickname =?", "ON DUPLICATE KEY UPDATE channel = ?, muted = ?, shadowmuted = ?, spyingwhispers = ?, nickname =?",
user.uuid().toString(), selectedName, user.muted(), user.shadowMuted(), user.spyingwhispers(), user.nickname(), user.uuid().toString(), selectedName, user.muted(), user.shadowMuted(), user.spyingwhispers(), user.nickname(),
selectedName, user.muted(), user.shadowMuted(), user.spyingwhispers(), user.nickname()); selectedName, user.muted(), user.shadowMuted(), user.spyingwhispers(), user.nickname());
this.carbonChat.getLogger().info("Saving user channel settings!"); this.carbonChat.logger().info("Saving user channel settings!");
// Save user channel settings // Save user channel settings
for (final Map.Entry<String, ? extends UserChannelSettings> entry : user.channelSettings().entrySet()) { for (final Map.Entry<String, ? extends UserChannelSettings> entry : user.channelSettings().entrySet()) {
final UserChannelSettings value = entry.getValue(); final UserChannelSettings value = entry.getValue();
@@ -211,7 +238,7 @@ public class MySQLUserService implements UserService {
value.spying(), value.ignored(), colorString); value.spying(), value.ignored(), colorString);
} }
this.carbonChat.getLogger().info("Saving user ignores!"); this.carbonChat.logger().info("Saving user ignores!");
// Save user ignore list (remove old entries then add new ones) // Save user ignore list (remove old entries then add new ones)
// TODO: keep DB up to date with settings as settings are mutated // TODO: keep DB up to date with settings as settings are mutated
stm.executeUpdateQuery("DELETE FROM sc_ignored_users WHERE uuid = ?", user.uuid().toString()); stm.executeUpdateQuery("DELETE FROM sc_ignored_users WHERE uuid = ?", user.uuid().toString());
@@ -1,4 +1,4 @@
package net.draycia.carbon.common.messaging; package net.draycia.carbon.common.utils;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
@@ -0,0 +1,42 @@
package net.draycia.carbon.common.utils;
import org.checkerframework.checker.nullness.qual.NonNull;
public class SQLCredentials {
private final @NonNull String username;
private final @NonNull String password;
private final @NonNull String database;
private final @NonNull String host;
private final int port;
public SQLCredentials(final @NonNull String username, final @NonNull String password,
final @NonNull String database, final @NonNull String host, final int port) {
this.username = username;
this.password = password;
this.database = database;
this.host = host;
this.port = port;
}
public @NonNull String username() {
return this.username;
}
public @NonNull String password() {
return this.password;
}
public @NonNull String database() {
return this.database;
}
public @NonNull String host() {
return this.host;
}
public int port() {
return this.port;
}
}