mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-02 14:38:49 +00:00
things
This commit is contained in:
1 parent
e263bccbfc
commit
8db4b9532c
63 files changed
+632
-472
No files matched your search
@@ -1,3 +1,7 @@
|
||||
plugins {
|
||||
id 'java-library'
|
||||
}
|
||||
|
||||
description 'CarbonChat-API'
|
||||
|
||||
dependencies {
|
||||
@@ -13,7 +17,10 @@ dependencies {
|
||||
compile 'net.kyori:event-api:3.0.0'
|
||||
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.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.UserService;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
@@ -23,12 +26,16 @@ public interface CarbonChat {
|
||||
|
||||
void reloadConfig();
|
||||
|
||||
@NonNull Logger logger();
|
||||
|
||||
@NonNull Path dataFolder();
|
||||
|
||||
@NonNull UserService userService();
|
||||
@NonNull <T extends ChatUser> UserService<T> userService();
|
||||
|
||||
@NonNull MessageProcessor messageProcessor();
|
||||
|
||||
@NonNull MessageService messageService();
|
||||
|
||||
@NonNull ChannelRegistry channelRegistry();
|
||||
|
||||
@NonNull CommandSettingsRegistry commandSettingsRegistry();
|
||||
|
||||
@@ -6,10 +6,10 @@ import java.util.List;
|
||||
|
||||
public class Context {
|
||||
|
||||
private @NonNull final String key;
|
||||
private @NonNull final Object value;
|
||||
private final @NonNull String key;
|
||||
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.value = value;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
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();
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ public class ChannelRegistry implements Registry<String, ChatChannel> {
|
||||
private ChatChannel defaultChannel = null;
|
||||
|
||||
@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);
|
||||
|
||||
if (this.defaultChannel == null && value.isDefault()) {
|
||||
@@ -29,16 +29,16 @@ public class ChannelRegistry implements Registry<String, ChatChannel> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable ChatChannel get(@NonNull final String key) {
|
||||
public @Nullable ChatChannel get(final @NonNull String 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());
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String key(@NonNull final ChatChannel value) {
|
||||
public @Nullable String key(final @NonNull ChatChannel value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import net.draycia.carbon.api.users.ChatUser;
|
||||
import net.kyori.adventure.audience.ForwardingAudience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
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.Nullable;
|
||||
|
||||
@@ -28,6 +29,13 @@ public interface ChatChannel extends ForwardingAudience {
|
||||
*/
|
||||
@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.
|
||||
* @param group The group.
|
||||
@@ -35,6 +43,8 @@ public interface ChatChannel extends ForwardingAudience {
|
||||
*/
|
||||
@Nullable String format(@NonNull String group);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
|
||||
+3
-3
@@ -14,12 +14,12 @@ public class CommandSettings {
|
||||
private final boolean enabled;
|
||||
|
||||
@Setting
|
||||
private @NonNull final String name;
|
||||
private final @NonNull String name;
|
||||
|
||||
@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.name = name;
|
||||
this.aliases = aliases;
|
||||
|
||||
+5
-5
@@ -37,26 +37,26 @@ public class CommandSettingsRegistry implements Registry<String, CommandSettings
|
||||
}
|
||||
|
||||
@Setting
|
||||
private @NonNull final Map<@NonNull String, @NonNull CommandSettings> registry = new HashMap<>();
|
||||
private final @NonNull Map<@NonNull String, @NonNull CommandSettings> registry = new HashMap<>();
|
||||
|
||||
@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);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable CommandSettings get(@NonNull final String key) {
|
||||
public @Nullable CommandSettings get(final @NonNull String 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());
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String key(@NonNull final CommandSettings value) {
|
||||
public @Nullable String key(final @NonNull CommandSettings value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -14,12 +14,12 @@ public class ChannelRegisterEvent implements CarbonEvent {
|
||||
@NonNull
|
||||
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.registry = registry;
|
||||
}
|
||||
|
||||
public void register(@NonNull final ChatChannel chatChannel) {
|
||||
public void register(final @NonNull ChatChannel chatChannel) {
|
||||
this.registry.register(chatChannel.key(), chatChannel);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ public class ChannelSwitchEvent implements CarbonEvent, Cancellable {
|
||||
private String failureMessage;
|
||||
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.user = user;
|
||||
this.failureMessage = failureMessage;
|
||||
|
||||
@@ -22,9 +22,9 @@ public class ChatComponentEvent implements CarbonEvent, Cancellable {
|
||||
@NonNull
|
||||
private final String originalMessage;
|
||||
|
||||
public ChatComponentEvent(@NonNull final ChatUser sender, @Nullable final ChatUser target,
|
||||
@NonNull final ChatChannel chatChannel, @NonNull final TextComponent component,
|
||||
@NonNull final String originalMessage) {
|
||||
public ChatComponentEvent(final @NonNull ChatUser sender, @Nullable final ChatUser target,
|
||||
final @NonNull ChatChannel chatChannel, final @NonNull TextComponent component,
|
||||
final @NonNull String originalMessage) {
|
||||
|
||||
this.sender = sender;
|
||||
this.target = target;
|
||||
@@ -58,7 +58,7 @@ public class ChatComponentEvent implements CarbonEvent, Cancellable {
|
||||
return this.chatChannel;
|
||||
}
|
||||
|
||||
public void channel(@NonNull final ChatChannel chatChannel) {
|
||||
public void channel(final @NonNull ChatChannel chatChannel) {
|
||||
this.chatChannel = chatChannel;
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ public class ChatComponentEvent implements CarbonEvent, Cancellable {
|
||||
return this.component;
|
||||
}
|
||||
|
||||
public void component(@NonNull final TextComponent component) {
|
||||
public void component(final @NonNull TextComponent component) {
|
||||
this.component = component;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,9 +21,9 @@ public class ChatFormatEvent implements CarbonEvent, Cancellable {
|
||||
@NonNull
|
||||
private String message;
|
||||
|
||||
public ChatFormatEvent(@NonNull final ChatUser sender, @Nullable final ChatUser target,
|
||||
@NonNull final ChatChannel chatChannel, @Nullable final String format,
|
||||
@NonNull final String message) {
|
||||
public ChatFormatEvent(final @NonNull ChatUser sender, @Nullable final ChatUser target,
|
||||
final @NonNull ChatChannel chatChannel, @Nullable final String format,
|
||||
final @NonNull String message) {
|
||||
|
||||
this.sender = sender;
|
||||
this.target = target;
|
||||
@@ -58,7 +58,7 @@ public class ChatFormatEvent implements CarbonEvent, Cancellable {
|
||||
return this.chatChannel;
|
||||
}
|
||||
|
||||
public void channel(@NonNull final ChatChannel chatChannel) {
|
||||
public void channel(final @NonNull ChatChannel chatChannel) {
|
||||
this.chatChannel = chatChannel;
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public class ChatFormatEvent implements CarbonEvent, Cancellable {
|
||||
return this.message;
|
||||
}
|
||||
|
||||
public void message(@NonNull final String message) {
|
||||
public void message(final @NonNull String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,8 +9,8 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class MessageContextEvent implements CarbonEvent, Cancellable {
|
||||
|
||||
private @NonNull final ChatChannel channel;
|
||||
private @NonNull final ChatUser user;
|
||||
private final @NonNull ChatChannel channel;
|
||||
private final @NonNull ChatUser user;
|
||||
private boolean cancelled = false;
|
||||
|
||||
public MessageContextEvent(final @NonNull ChatChannel channel, final @NonNull ChatUser user) {
|
||||
@@ -28,7 +28,7 @@ public class MessageContextEvent implements CarbonEvent, Cancellable {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
public Context context(@NonNull final String key) {
|
||||
public Context context(final @NonNull String key) {
|
||||
return this.channel.context(key);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,8 +19,8 @@ public class PreChatFormatEvent implements CarbonEvent, Cancellable {
|
||||
@NonNull
|
||||
private String message;
|
||||
|
||||
public PreChatFormatEvent(@NonNull final ChatUser user, @NonNull final ChatChannel chatChannel,
|
||||
@Nullable final String format, @NonNull final String message) {
|
||||
public PreChatFormatEvent(final @NonNull ChatUser user, final @NonNull ChatChannel chatChannel,
|
||||
@Nullable final String format, final @NonNull String message) {
|
||||
|
||||
this.user = user;
|
||||
this.chatChannel = chatChannel;
|
||||
@@ -48,7 +48,7 @@ public class PreChatFormatEvent implements CarbonEvent, Cancellable {
|
||||
return this.chatChannel;
|
||||
}
|
||||
|
||||
public void channel(@NonNull final ChatChannel chatChannel) {
|
||||
public void channel(final @NonNull ChatChannel chatChannel) {
|
||||
this.chatChannel = chatChannel;
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ public class PreChatFormatEvent implements CarbonEvent, Cancellable {
|
||||
return this.message;
|
||||
}
|
||||
|
||||
public void message(@NonNull final String message) {
|
||||
public void message(final @NonNull String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,9 +20,9 @@ public class PrivateMessageEvent implements CarbonEvent, Cancellable {
|
||||
private final String message;
|
||||
private boolean cancelled = false;
|
||||
|
||||
public PrivateMessageEvent(@NonNull final ChatUser sender, @NonNull final ChatUser target,
|
||||
@NonNull final Component senderComponent, @NonNull final Component targetComponent,
|
||||
@NonNull final String message) {
|
||||
public PrivateMessageEvent(final @NonNull ChatUser sender, final @NonNull ChatUser target,
|
||||
final @NonNull Component senderComponent, final @NonNull Component targetComponent,
|
||||
final @NonNull String message) {
|
||||
|
||||
this.sender = sender;
|
||||
this.target = target;
|
||||
|
||||
+4
-4
@@ -9,9 +9,9 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class ReceiverContextEvent implements CarbonEvent, Cancellable {
|
||||
|
||||
private @NonNull final ChatChannel channel;
|
||||
private @NonNull final ChatUser sender;
|
||||
private @NonNull final ChatUser recipient;
|
||||
private final @NonNull ChatChannel channel;
|
||||
private final @NonNull ChatUser sender;
|
||||
private final @NonNull ChatUser recipient;
|
||||
private boolean cancelled = false;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public Context context(@NonNull final String key) {
|
||||
public Context context(final @NonNull String 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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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>() {
|
||||
@Override
|
||||
public int postOrder() {
|
||||
@@ -31,17 +31,17 @@ public final class CarbonEvents {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NonNull final T event) {
|
||||
public void invoke(final @NonNull T 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);
|
||||
}
|
||||
|
||||
public static PostResult post(@NonNull final CarbonEvent event) {
|
||||
public static PostResult post(final @NonNull CarbonEvent event) {
|
||||
return EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,12 +11,12 @@ import java.util.function.Consumer;
|
||||
|
||||
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;
|
||||
|
||||
import com.intellectualsites.commands.sender.CommandSender;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
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.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public interface ChatUser extends Audience, CommandSender {
|
||||
public interface ChatUser extends Audience {
|
||||
|
||||
@NonNull UUID uuid();
|
||||
|
||||
@@ -17,7 +19,6 @@ public interface ChatUser extends Audience, CommandSender {
|
||||
|
||||
boolean online();
|
||||
|
||||
@Override
|
||||
boolean hasPermission(@NonNull String permission);
|
||||
|
||||
@Nullable String nickname();
|
||||
@@ -36,7 +37,7 @@ public interface ChatUser extends Audience, CommandSender {
|
||||
|
||||
@Nullable ChatChannel selectedChannel();
|
||||
|
||||
default void selectedChannel(@NonNull final ChatChannel channel) {
|
||||
default void selectedChannel(final @NonNull ChatChannel channel) {
|
||||
this.selectedChannel(channel, false);
|
||||
}
|
||||
|
||||
@@ -46,6 +47,8 @@ public interface ChatUser extends Audience, CommandSender {
|
||||
|
||||
@NonNull UserChannelSettings channelSettings(@NonNull ChatChannel channel);
|
||||
|
||||
@NonNull Map<@NonNull String, @NonNull ? extends UserChannelSettings> channelSettings();
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
default boolean ignoringUser(@NonNull final ChatUser user) {
|
||||
default boolean ignoringUser(final @NonNull ChatUser user) {
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
@@ -10,10 +10,6 @@ dependencies {
|
||||
|
||||
compile project(":CarbonChat-Common")
|
||||
|
||||
// Databases
|
||||
compile 'co.aikar:idb-bukkit:1.0.0-SNAPSHOT'
|
||||
compile 'com.zaxxer:HikariCP:2.4.1'
|
||||
|
||||
// Messaging
|
||||
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.channels.ChannelRegistry;
|
||||
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.common.adventure.FormatType;
|
||||
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.api.users.UserService;
|
||||
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.FunctionalityConstants;
|
||||
import net.draycia.carbon.util.Metrics;
|
||||
@@ -51,12 +54,15 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.spongepowered.configurate.BasicConfigurationNode;
|
||||
import org.spongepowered.configurate.objectmapping.ObjectMappingException;
|
||||
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
||||
|
||||
@@ -68,13 +74,15 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
||||
private CommandSettingsRegistry commandSettings;
|
||||
private AdventureManager messageProcessor;
|
||||
|
||||
private UserService userService;
|
||||
private UserService<BukkitChatUser> userService;
|
||||
private MessageManager messageManager;
|
||||
|
||||
private FilterContext filterContext;
|
||||
|
||||
private CarbonTranslations translations;
|
||||
|
||||
private Logger logger;
|
||||
|
||||
public static final LegacyComponentSerializer LEGACY =
|
||||
LegacyComponentSerializer.builder()
|
||||
.extractUrls()
|
||||
@@ -92,6 +100,8 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
this.logger = LoggerFactory.getLogger(this.getName());
|
||||
|
||||
CommandAPI.onEnable(this);
|
||||
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");
|
||||
|
||||
if (storageType.equalsIgnoreCase("mysql")) {
|
||||
this.getLogger().info("Enabling MySQL storage!");
|
||||
this.logger().info("Enabling MySQL storage!");
|
||||
this.userService = new MySQLUserService(this);
|
||||
} else if (storageType.equalsIgnoreCase("json")) {
|
||||
this.getLogger().info("Enabling JSON storage!");
|
||||
this.logger().info("Enabling JSON storage!");
|
||||
this.userService = new JSONUserService(this);
|
||||
} 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);
|
||||
}
|
||||
|
||||
// Setup listeners
|
||||
this.setupCommands();
|
||||
this.setupListeners();
|
||||
this.registerContexts();
|
||||
|
||||
new CarbonPlaceholders(this).register();
|
||||
|
||||
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
|
||||
throw new IllegalArgumentException("Non-players not supported yet!");
|
||||
}
|
||||
}, user -> {
|
||||
return Bukkit.getPlayer(user.uuid());
|
||||
});
|
||||
}, user -> Bukkit.getPlayer(user.uuid()));
|
||||
|
||||
CommandRegistrar.registerCommands(manager);
|
||||
} catch (final Exception e) {
|
||||
@@ -267,7 +276,7 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public UserService userService() {
|
||||
public UserService<BukkitChatUser> userService() {
|
||||
return this.userService;
|
||||
}
|
||||
|
||||
@@ -286,8 +295,29 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
||||
return this.translations;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull ModerationSettings moderationSettings() {
|
||||
return this.moderationSettings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull MessageProcessor 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();
|
||||
}
|
||||
|
||||
}
|
||||
+98
-234
@@ -1,7 +1,8 @@
|
||||
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.CarbonChatBukkit;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.events.misc.CarbonEvents;
|
||||
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.TextColor;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import net.luckperms.api.model.group.Group;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class CarbonChatChannel implements ChatChannel {
|
||||
@@ -35,24 +33,29 @@ public class CarbonChatChannel implements ChatChannel {
|
||||
private final String key;
|
||||
|
||||
@NonNull
|
||||
private final CarbonChatBukkit carbonChat;
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
@Nullable
|
||||
private final ConfigurationSection config;
|
||||
@NonNull
|
||||
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.carbonChat = carbonChat;
|
||||
this.config = config;
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
public @NonNull ChannelSettings settings() {
|
||||
return this.settings;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public CarbonChatBukkit carbonChat() {
|
||||
public CarbonChat carbonChat() {
|
||||
return this.carbonChat;
|
||||
}
|
||||
|
||||
@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);
|
||||
|
||||
CarbonEvents.post(event);
|
||||
@@ -61,7 +64,7 @@ public class CarbonChatChannel implements ChatChannel {
|
||||
}
|
||||
|
||||
@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");
|
||||
}
|
||||
|
||||
@@ -70,40 +73,38 @@ public class CarbonChatChannel implements ChatChannel {
|
||||
public List<@NonNull ChatUser> audiences() {
|
||||
final List<ChatUser> audience = new ArrayList<>();
|
||||
|
||||
for (final Player player : Bukkit.getOnlinePlayers()) {
|
||||
final ChatUser playerUser = this.carbonChat.userService().wrap(player.getUniqueId());
|
||||
|
||||
if (this.canPlayerSee(playerUser, true)) {
|
||||
audience.add(playerUser);
|
||||
for (final ChatUser user : this.carbonChat.userService().onlineUsers()) {
|
||||
if (this.canPlayerSee(user, true)) {
|
||||
audience.add(user);
|
||||
}
|
||||
}
|
||||
|
||||
return audience;
|
||||
}
|
||||
|
||||
private void updateUserNickname(@NonNull final ChatUser user) {
|
||||
final Player player = Bukkit.getPlayer(user.uuid());
|
||||
|
||||
if (player != null) {
|
||||
String nickname = user.nickname();
|
||||
|
||||
if (nickname != null) {
|
||||
final Component component = this.carbonChat.messageProcessor().processMessage(nickname);
|
||||
nickname = CarbonChatBukkit.LEGACY.serialize(component);
|
||||
|
||||
player.setDisplayName(nickname);
|
||||
|
||||
if (this.carbonChat.getConfig().getBoolean("nicknames-set-tab-name")) {
|
||||
player.setPlayerListName(nickname);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// private void updateUserNickname(final @NonNull ChatUser user) {
|
||||
// final Player player = Bukkit.getPlayer(user.uuid());
|
||||
//
|
||||
// if (player != null) {
|
||||
// String nickname = user.nickname();
|
||||
//
|
||||
// if (nickname != null) {
|
||||
// final Component component = this.carbonChat.messageProcessor().processMessage(nickname);
|
||||
// nickname = CarbonChat.LEGACY.serialize(component);
|
||||
//
|
||||
// player.setDisplayName(nickname);
|
||||
//
|
||||
// if (this.carbonChat.getConfig().getBoolean("nicknames-set-tab-name")) {
|
||||
// player.setPlayerListName(nickname);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public Component sendMessage(@NonNull final ChatUser user, @NonNull final Collection<@NonNull ChatUser> recipients, @NonNull final String message, final boolean fromRemote) {
|
||||
this.updateUserNickname(user);
|
||||
public Component sendMessage(final @NonNull ChatUser user, final @NonNull Collection<@NonNull ChatUser> recipients, final @NonNull String message, final boolean fromRemote) {
|
||||
//this.updateUserNickname(user);
|
||||
|
||||
final MessageContextEvent event = new MessageContextEvent(this, user);
|
||||
|
||||
@@ -132,13 +133,7 @@ public class CarbonChatChannel implements ChatChannel {
|
||||
if (user.nickname() != null) {
|
||||
displayName = user.nickname();
|
||||
} else {
|
||||
final OfflinePlayer player = Bukkit.getOfflinePlayer(user.uuid());
|
||||
|
||||
if (player.isOnline()) {
|
||||
displayName = player.getPlayer().getDisplayName();
|
||||
} else {
|
||||
displayName = player.getName();
|
||||
}
|
||||
displayName = user.displayName();
|
||||
}
|
||||
|
||||
// Iterate through players who should receive messages in this channel
|
||||
@@ -198,13 +193,8 @@ public class CarbonChatChannel implements ChatChannel {
|
||||
|
||||
CarbonEvents.post(consoleEvent);
|
||||
|
||||
// Route message to bungee / discord (if message originates from this server)
|
||||
// Use instanceof and not isOnline, if this message originates from another then the instanceof will
|
||||
// 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());
|
||||
if (user.online() && !fromRemote && this.crossServer()) {
|
||||
this.sendMessageToBungee(user.uuid(), consoleEvent.component());
|
||||
}
|
||||
|
||||
return consoleEvent.component();
|
||||
@@ -212,12 +202,12 @@ public class CarbonChatChannel implements ChatChannel {
|
||||
|
||||
@Override
|
||||
@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);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String format(@NonNull final ChatUser user) {
|
||||
public String format(final @NonNull ChatUser user) {
|
||||
for (final String group : this.groupOverrides()) {
|
||||
if (this.userHasGroup(user, 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) {
|
||||
if (user.permissible()) {
|
||||
if (this.carbonChat.permission().playerInGroup(Bukkit.getPlayer(user.uuid()), group)) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (this.carbonChat.permission().playerInGroup(null, Bukkit.getOfflinePlayer(user.uuid()), group)) {
|
||||
return true;
|
||||
}
|
||||
private boolean userHasGroup(final @NonNull ChatUser user, final @NonNull String group) {
|
||||
if (user.hasGroup(group)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (user.permissible() && this.permissionGroupMatching()) {
|
||||
if (this.permissionGroupMatching()) {
|
||||
return user.hasPermission("carbonchat.group." + group);
|
||||
}
|
||||
|
||||
@@ -254,16 +238,8 @@ public class CarbonChatChannel implements ChatChannel {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private String firstFoundUserFormat(@NonNull final ChatUser user) {
|
||||
final String[] playerGroups;
|
||||
|
||||
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) {
|
||||
private String firstFoundUserFormat(final @NonNull ChatUser user) {
|
||||
for (final Group group : user.groups()) {
|
||||
final String groupFormat = this.format(group);
|
||||
|
||||
if (groupFormat != null) {
|
||||
@@ -275,15 +251,8 @@ public class CarbonChatChannel implements ChatChannel {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private String primaryGroupFormat(@NonNull final ChatUser user) {
|
||||
final String primaryGroup;
|
||||
|
||||
if (user.permissible()) {
|
||||
primaryGroup = this.carbonChat.permission().getPrimaryGroup(Bukkit.getPlayer(user.uuid()));
|
||||
} else {
|
||||
primaryGroup = this.carbonChat.permission().getPrimaryGroup(null, Bukkit.getOfflinePlayer(user.uuid()));
|
||||
}
|
||||
|
||||
private String primaryGroupFormat(final @NonNull ChatUser user) {
|
||||
final Group primaryGroup = user.primaryGroup();
|
||||
final String primaryGroupFormat = this.format(primaryGroup);
|
||||
|
||||
if (primaryGroupFormat != null) {
|
||||
@@ -300,11 +269,17 @@ public class CarbonChatChannel implements ChatChannel {
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String format(@NonNull final String group) {
|
||||
return this.getString("formats." + group);
|
||||
public String format(final @NonNull Group 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)) {
|
||||
return target.channelSettings(this).spying();
|
||||
}
|
||||
@@ -313,7 +288,7 @@ public class CarbonChatChannel implements ChatChannel {
|
||||
}
|
||||
|
||||
@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()) {
|
||||
if (!user.ignoringUser(player)) {
|
||||
user.sendMessage(component);
|
||||
@@ -321,15 +296,15 @@ public class CarbonChatChannel implements ChatChannel {
|
||||
}
|
||||
}
|
||||
|
||||
public void sendMessageToBungee(@NonNull final Player player, @NonNull final Component component) {
|
||||
this.carbonChat.messageManager().sendMessage("channel-component", player.getUniqueId(), byteArray -> {
|
||||
public void sendMessageToBungee(final @NonNull UUID uuid, final @NonNull Component component) {
|
||||
this.carbonChat.messageService().sendMessage("channel-component", uuid, byteArray -> {
|
||||
byteArray.writeUTF(this.key());
|
||||
byteArray.writeUTF(this.carbonChat.messageProcessor().audiences().gsonSerializer().serialize(component));
|
||||
});
|
||||
}
|
||||
|
||||
@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 (target.channelSettings(this).spying()) {
|
||||
return true;
|
||||
@@ -347,7 +322,7 @@ public class CarbonChatChannel implements ChatChannel {
|
||||
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)) {
|
||||
return false;
|
||||
@@ -362,20 +337,20 @@ public class CarbonChatChannel implements ChatChannel {
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public TextColor channelColor(@NonNull final ChatUser user) {
|
||||
public TextColor channelColor(final @NonNull ChatUser user) {
|
||||
final TextColor userColor = user.channelSettings(this).color();
|
||||
|
||||
if (userColor != null) {
|
||||
return userColor;
|
||||
}
|
||||
|
||||
final String input = this.getString("color");
|
||||
final String input = this.settings().color();
|
||||
|
||||
final TextColor color = CarbonUtils.parseColor(user, input);
|
||||
|
||||
if (color == null && this.carbonChat.getConfig().getBoolean("show-tips")) {
|
||||
this.carbonChat.getLogger().warning("Tip: Channel color found (" + input + ") is invalid!");
|
||||
this.carbonChat.getLogger().warning("Falling back to #FFFFFF");
|
||||
this.carbonChat.logger().error("Tip: Channel color found (" + input + ") is invalid!");
|
||||
this.carbonChat.logger().error("Falling back to #FFFFFF");
|
||||
|
||||
return NamedTextColor.WHITE;
|
||||
}
|
||||
@@ -384,233 +359,133 @@ public class CarbonChatChannel implements ChatChannel {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private String defaultFormatName() {
|
||||
return this.getString("default-group");
|
||||
public String defaultFormatName() {
|
||||
return this.settings().defaultFormatName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDefault() {
|
||||
if (this.config != null && this.config.contains("default")) {
|
||||
return this.config.getBoolean("default");
|
||||
}
|
||||
|
||||
return false;
|
||||
return this.settings().isDefault();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean ignorable() {
|
||||
return this.getBoolean("ignorable");
|
||||
return this.settings().ignorable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean crossServer() {
|
||||
return this.getBoolean("is-cross-server");
|
||||
return this.settings().crossServer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean honorsRecipientList() {
|
||||
return this.getBoolean("honors-recipient-list");
|
||||
return this.settings().honorsRecipientList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean permissionGroupMatching() {
|
||||
return this.getBoolean("permission-group-matching");
|
||||
return this.settings().permissionGroupMatching();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public List<@NonNull String> groupOverrides() {
|
||||
return this.getStringList("group-overrides");
|
||||
return this.settings().groupOverrides();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public String name() {
|
||||
final String name = this.getString("name");
|
||||
return name == null ? this.key : name;
|
||||
return this.settings().name();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String messagePrefix() {
|
||||
if (this.config != null && this.config.contains("message-prefix")) {
|
||||
return this.config.getString("message-prefix");
|
||||
}
|
||||
|
||||
return null;
|
||||
return this.settings().messagePrefix();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String switchMessage() {
|
||||
return this.getString("switch-message");
|
||||
return this.settings().switchMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String switchOtherMessage() {
|
||||
return this.getString("switch-other-message");
|
||||
return this.settings().switchOtherMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String switchFailureMessage() {
|
||||
return this.getString("switch-failure-message");
|
||||
return this.settings().switchFailureMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String cannotIgnoreMessage() {
|
||||
return this.getString("cannot-ignore-message");
|
||||
return this.settings().cannotIgnoreMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String toggleOffMessage() {
|
||||
return this.getString("toggle-off-message");
|
||||
return this.settings().toggleOffMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String toggleOnMessage() {
|
||||
return this.getString("toggle-on-message");
|
||||
return this.settings().toggleOnMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String toggleOtherOnMessage() {
|
||||
return this.getString("toggle-other-on");
|
||||
return this.settings().toggleOtherOnMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String toggleOtherOffMessage() {
|
||||
return this.getString("toggle-other-off");
|
||||
return this.settings().toggleOtherOffMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String cannotUseMessage() {
|
||||
return this.getString("cannot-use-channel");
|
||||
return this.settings().cannotUseMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean primaryGroupOnly() {
|
||||
return this.getBoolean("primary-group-only");
|
||||
return this.settings().primaryGroupOnly();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldCancelChatEvent() {
|
||||
return this.getBoolean("cancel-message-event");
|
||||
return this.settings().shouldCancelChatEvent();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public List<@NonNull Pattern> itemLinkPatterns() {
|
||||
final ArrayList<Pattern> itemPatterns = new ArrayList<>();
|
||||
|
||||
for (final String entry : this.carbonChat.getConfig().getStringList("item-link-placeholders")) {
|
||||
itemPatterns.add(Pattern.compile(Pattern.quote(entry)));
|
||||
}
|
||||
|
||||
return itemPatterns;
|
||||
return this.settings().itemLinkPatterns();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Context context(@NonNull final String key) {
|
||||
final ConfigurationSection section = this.config == null ? null : this.config.getConfigurationSection("contexts");
|
||||
|
||||
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);
|
||||
public String aliases() {
|
||||
return this.settings().aliases();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
@SuppressWarnings("checkstyle:MethodName")
|
||||
private String getString(@NonNull final String 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;
|
||||
public Context context(final @NonNull String key) {
|
||||
return this.settings().contexts().get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -619,15 +494,4 @@ public class CarbonChatChannel implements ChatChannel {
|
||||
return this.key;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String aliases() {
|
||||
final String aliases = this.getString("aliases");
|
||||
|
||||
if (aliases == null) {
|
||||
return this.key();
|
||||
}
|
||||
|
||||
return aliases;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -16,7 +16,7 @@ public class EconomyContext {
|
||||
@NonNull
|
||||
private final Economy economy;
|
||||
|
||||
public EconomyContext(@NonNull final CarbonChatBukkit carbonChat) {
|
||||
public EconomyContext(final @NonNull CarbonChatBukkit carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
this.economy = this.carbonChat.getServer().getServicesManager().getRegistration(Economy.class).getProvider();
|
||||
|
||||
|
||||
+2
-2
@@ -29,7 +29,7 @@ public class FilterContext {
|
||||
@NonNull
|
||||
private final List<@NonNull Pattern> blockedWords = new ArrayList<>();
|
||||
|
||||
public FilterContext(@NonNull final CarbonChat carbonChat) {
|
||||
public FilterContext(final @NonNull CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
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");
|
||||
|
||||
if (context == null) {
|
||||
|
||||
+3
-3
@@ -27,7 +27,7 @@ public final class TownyContext implements Listener {
|
||||
@NonNull
|
||||
private final CarbonChatBukkit carbonChat;
|
||||
|
||||
public TownyContext(@NonNull final CarbonChatBukkit carbonChat) {
|
||||
public TownyContext(final @NonNull CarbonChatBukkit carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
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 {
|
||||
return TownyAPI.getInstance().getDataSource().getResident(Bukkit.getPlayer(user.uuid()).getName()).hasTown();
|
||||
} catch (final NotRegisteredException exception) {
|
||||
@@ -104,7 +104,7 @@ public final class TownyContext implements Listener {
|
||||
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) {
|
||||
return false;
|
||||
}
|
||||
|
||||
+5
-5
@@ -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()) {
|
||||
return this.isInRegion(context.asString(), player);
|
||||
}
|
||||
@@ -63,7 +63,7 @@ public final class WorldGuardContext {
|
||||
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 user2InRegion = false;
|
||||
|
||||
@@ -89,7 +89,7 @@ public final class WorldGuardContext {
|
||||
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 user2Location = BukkitAdapter.adapt(user2.getLocation());
|
||||
|
||||
@@ -108,7 +108,7 @@ public final class WorldGuardContext {
|
||||
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 World world = BukkitAdapter.adapt(player.getWorld());
|
||||
final ProtectedRegion protection = container.get(world).getRegion(region);
|
||||
@@ -116,7 +116,7 @@ public final class WorldGuardContext {
|
||||
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();
|
||||
|
||||
return region.contains(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
|
||||
+3
-3
@@ -25,7 +25,7 @@ public final class mcMMOContext implements Listener {
|
||||
@NonNull
|
||||
private static final String KEY = "mcmmo-party";
|
||||
|
||||
public mcMMOContext(@NonNull final CarbonChatBukkit carbonChat) {
|
||||
public mcMMOContext(final @NonNull CarbonChatBukkit carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
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()));
|
||||
}
|
||||
|
||||
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) {
|
||||
return false;
|
||||
}
|
||||
|
||||
+5
-5
@@ -22,13 +22,13 @@ public class BukkitChatListener implements Listener {
|
||||
@NonNull
|
||||
private final CarbonChatBukkit carbonChat;
|
||||
|
||||
public BukkitChatListener(@NonNull final CarbonChatBukkit carbonChat) {
|
||||
public BukkitChatListener(final @NonNull CarbonChatBukkit carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
}
|
||||
|
||||
// Chat messages
|
||||
@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());
|
||||
ChatChannel channel = user.selectedChannel();
|
||||
|
||||
@@ -92,9 +92,9 @@ public class BukkitChatListener implements Listener {
|
||||
this.carbonChat.messageProcessor().audiences().console().sendMessage(component);
|
||||
|
||||
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.getLogger().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 event! I cannot set the message format due to this. :(");
|
||||
this.carbonChat.logger().info("Tip: To 'solve' this, do a binary search and see which plugin is triggering");
|
||||
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
|
||||
private String defaultChannelKey = null;
|
||||
|
||||
public ChannelManager(@NonNull final CarbonChatBukkit carbonChat) {
|
||||
public ChannelManager(final @NonNull CarbonChatBukkit carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
this.registry = new ChannelRegistry();
|
||||
|
||||
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 String name = section.getString("name");
|
||||
|
||||
if (name != null && name.length() > 16) {
|
||||
this.carbonChat.getLogger().warning("Channel name [" + name + "] too long! Max length: 16.");
|
||||
this.carbonChat.getLogger().warning("Skipping channel, please check your settings!");
|
||||
this.carbonChat.logger().error("Channel name [" + name + "] too long! Max length: 16.");
|
||||
this.carbonChat.logger().error("Skipping channel, please check your settings!");
|
||||
return null;
|
||||
}
|
||||
|
||||
return channel;
|
||||
}
|
||||
|
||||
public void registerChannel(@NonNull final ChatChannel channel) {
|
||||
public void registerChannel(final @NonNull ChatChannel channel) {
|
||||
this.registry().register(channel.key(), channel);
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ public class ChannelManager {
|
||||
prefix = "";
|
||||
}
|
||||
|
||||
this.carbonChat.getLogger().info("Registering channel: " + prefix + channel.name());
|
||||
this.carbonChat.logger().info("Registering channel: " + prefix + channel.name());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-6
@@ -33,7 +33,7 @@ public class BungeeMessageService implements MessageService {
|
||||
@NonNull
|
||||
private final UUID serverUUID = UUID.randomUUID();
|
||||
|
||||
public BungeeMessageService(@NonNull final CarbonChatBukkit carbonChat) {
|
||||
public BungeeMessageService(final @NonNull CarbonChatBukkit carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
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);
|
||||
|
||||
if (user != null) {
|
||||
@@ -84,23 +84,23 @@ public class BungeeMessageService implements MessageService {
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterMessageListener(@NonNull final String key) {
|
||||
public void unregisterMessageListener(final @NonNull String key) {
|
||||
this.userLoadedListeners.remove(key);
|
||||
this.userNotLoadedListeners.remove(key);
|
||||
}
|
||||
|
||||
@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();
|
||||
|
||||
msg.writeLong(this.serverUUID.getMostSignificantBits());
|
||||
|
||||
+58
-9
@@ -14,7 +14,11 @@ import net.kyori.adventure.audience.ForwardingAudience;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.sound.Sound;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.luckperms.api.LuckPerms;
|
||||
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.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -23,6 +27,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -55,7 +60,7 @@ public class BukkitChatUser implements ChatUser, ForwardingAudience {
|
||||
this.carbonChat = (CarbonChatBukkit) Bukkit.getPluginManager().getPlugin("CarbonChat");
|
||||
}
|
||||
|
||||
public BukkitChatUser(@NonNull final UUID uuid) {
|
||||
public BukkitChatUser(final @NonNull UUID uuid) {
|
||||
this();
|
||||
this.uuid = uuid;
|
||||
}
|
||||
@@ -63,7 +68,12 @@ public class BukkitChatUser implements ChatUser, ForwardingAudience {
|
||||
@Override
|
||||
@NonNull
|
||||
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
|
||||
@@ -84,7 +94,7 @@ public class BukkitChatUser implements ChatUser, ForwardingAudience {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(@NonNull final String permission) {
|
||||
public boolean hasPermission(final @NonNull String permission) {
|
||||
return LuckPermsProvider.get().getUserManager().getUser(this.uuid())
|
||||
.getCachedData().getPermissionData().checkPermission(permission).asBoolean();
|
||||
}
|
||||
@@ -156,7 +166,7 @@ public class BukkitChatUser implements ChatUser, ForwardingAudience {
|
||||
}
|
||||
|
||||
@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 ChannelSwitchEvent event = new ChannelSwitchEvent(chatChannel, this, failureMessage);
|
||||
@@ -194,12 +204,12 @@ public class BukkitChatUser implements ChatUser, ForwardingAudience {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean ignoringUser(@NonNull final UUID uuid) {
|
||||
public boolean ignoringUser(final @NonNull UUID uuid) {
|
||||
return this.ignoredUsers.contains(uuid);
|
||||
}
|
||||
|
||||
@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) {
|
||||
this.ignoredUsers.add(uuid);
|
||||
} else {
|
||||
@@ -215,11 +225,50 @@ public class BukkitChatUser implements ChatUser, ForwardingAudience {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public List<@NonNull UUID> ignoredUsers() {
|
||||
public Iterable<@NonNull UUID> 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
|
||||
public void muted(final boolean muted, final boolean fromRemote) {
|
||||
this.muted = muted;
|
||||
@@ -272,7 +321,7 @@ public class BukkitChatUser implements ChatUser, ForwardingAudience {
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public UserChannelSettings channelSettings(@NonNull final ChatChannel channel) {
|
||||
public UserChannelSettings channelSettings(final @NonNull ChatChannel channel) {
|
||||
return this.channelSettings.computeIfAbsent(channel.key(), name -> {
|
||||
return new SimpleUserChannelSettings(this.uuid, channel.key());
|
||||
});
|
||||
@@ -300,7 +349,7 @@ public class BukkitChatUser implements ChatUser, ForwardingAudience {
|
||||
}
|
||||
|
||||
@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)) {
|
||||
return;
|
||||
}
|
||||
|
||||
+4
-4
@@ -24,7 +24,7 @@ public class SimpleUserChannelSettings implements UserChannelSettings {
|
||||
@MonotonicNonNull // @NonNull but not initialised in all constructors.
|
||||
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.channel = channel;
|
||||
}
|
||||
@@ -44,7 +44,7 @@ public class SimpleUserChannelSettings implements UserChannelSettings {
|
||||
this.spying = spying;
|
||||
|
||||
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.writeBoolean(spying);
|
||||
});
|
||||
@@ -61,7 +61,7 @@ public class SimpleUserChannelSettings implements UserChannelSettings {
|
||||
this.ignored = ignored;
|
||||
|
||||
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.writeBoolean(ignored);
|
||||
});
|
||||
@@ -87,7 +87,7 @@ public class SimpleUserChannelSettings implements UserChannelSettings {
|
||||
}
|
||||
|
||||
if (!fromRemote) {
|
||||
this.carbonChat.messageManager().sendMessage("channel-color", this.uuid, byteArray -> {
|
||||
this.carbonChat.messageService().sendMessage("channel-color", this.uuid, byteArray -> {
|
||||
byteArray.writeUTF(color.asHexString());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ public class CarbonPlaceholders extends PlaceholderExpansion {
|
||||
@NonNull
|
||||
private final CarbonChatBukkit carbonChat;
|
||||
|
||||
public CarbonPlaceholders(@NonNull final CarbonChatBukkit carbonChat) {
|
||||
public CarbonPlaceholders(final @NonNull CarbonChatBukkit carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public class CarbonPlaceholders extends PlaceholderExpansion {
|
||||
|
||||
@Override
|
||||
@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();
|
||||
|
||||
if (key.startsWith("can_use_")) {
|
||||
|
||||
@@ -66,7 +66,7 @@ public final class CarbonUtils {
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static Component createComponent(@NonNull final Player player) {
|
||||
public static Component createComponent(final @NonNull Player player) {
|
||||
if (!FunctionalityConstants.HAS_HOVER_EVENT_METHOD) {
|
||||
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());
|
||||
|
||||
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 {
|
||||
runnable.run();
|
||||
return true;
|
||||
|
||||
@@ -12,4 +12,9 @@ dependencies {
|
||||
compileOnly 'com.google.code.gson:gson:2.8.0'
|
||||
|
||||
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'
|
||||
}
|
||||
+3
-3
@@ -17,13 +17,13 @@ public class AdventureManager implements MessageProcessor {
|
||||
@NonNull
|
||||
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.formatType = formatType;
|
||||
}
|
||||
|
||||
@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()) {
|
||||
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) {
|
||||
final String placeholder = placeholders[i];
|
||||
final String replacement = placeholders[i + 1];
|
||||
|
||||
+106
@@ -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() {
|
||||
}
|
||||
|
||||
}
|
||||
+3
-3
@@ -18,7 +18,7 @@ public class AliasedChannelCommand {
|
||||
|
||||
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.chatChannel = chatChannel;
|
||||
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();
|
||||
|
||||
if (user.channelSettings(this.chatChannel()).ignored()) {
|
||||
@@ -56,7 +56,7 @@ public class AliasedChannelCommand {
|
||||
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 -> {
|
||||
final Component component = this.chatChannel().sendMessage(context.getSender(), message, false);
|
||||
|
||||
|
||||
+2
-2
@@ -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 ChatChannel channel = context.getRequired("channel");
|
||||
|
||||
@@ -63,7 +63,7 @@ public class ChannelCommand {
|
||||
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 ChatChannel channel = context.getRequired("channel");
|
||||
final String message = context.getRequired("message");
|
||||
|
||||
+6
-6
@@ -22,7 +22,7 @@ public class ChannelListCommand {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public ChannelListCommand(@NonNull final CommandManager<ChatUser> commandManager) {
|
||||
public ChannelListCommand(final @NonNull CommandManager<ChatUser> commandManager) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
public void toggleOther(@NonNull final CommandContext<ChatUser> context) {
|
||||
public void toggleOther(final @NonNull CommandContext<ChatUser> context) {
|
||||
final ChatUser sender = context.getSender();
|
||||
final ChatUser user = context.getRequired("user");
|
||||
|
||||
@@ -69,8 +69,8 @@ public class ChannelListCommand {
|
||||
this.listAndSend(sender, user, allChannels);
|
||||
}
|
||||
|
||||
private void listAndSend(@NonNull final ChatUser sender, @NonNull final ChatUser user,
|
||||
@NonNull final Iterator<ChatChannel> allChannels) {
|
||||
private void listAndSend(final @NonNull ChatUser sender, final @NonNull ChatUser user,
|
||||
final @NonNull Iterator<ChatChannel> allChannels) {
|
||||
ChatChannel channel;
|
||||
final List<ChatChannel> canSee = 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();
|
||||
// TODO: Larry, why did you double assign the listSeparatorComponent?
|
||||
final Component listSeparatorComponent = TextComponent.of(listSeparator);
|
||||
|
||||
+2
-2
@@ -14,7 +14,7 @@ public class ChatReloadCommand {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public ChatReloadCommand(@NonNull final CommandManager<ChatUser> commandManager) {
|
||||
public ChatReloadCommand(final @NonNull CommandManager<ChatUser> commandManager) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
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();
|
||||
|
||||
final Component message = this.carbonChat.messageProcessor()
|
||||
|
||||
+2
-2
@@ -14,7 +14,7 @@ public class ClearChatCommand {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public ClearChatCommand(@NonNull final CommandManager<ChatUser> commandManager) {
|
||||
public ClearChatCommand(final @NonNull CommandManager<ChatUser> commandManager) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
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 format = this.carbonChat.moderationSettings().clearChat().message();
|
||||
final Component component = this.carbonChat.messageProcessor().processMessage(format, "br", "\n");
|
||||
|
||||
+2
-2
@@ -15,7 +15,7 @@ public class IgnoreCommand {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public IgnoreCommand(@NonNull final CommandManager<ChatUser> commandManager) {
|
||||
public IgnoreCommand(final @NonNull CommandManager<ChatUser> commandManager) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
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 targetUser = context.getRequired("user");
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ public class MeCommand {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public MeCommand(@NonNull final CommandManager<ChatUser> commandManager) {
|
||||
public MeCommand(final @NonNull CommandManager<ChatUser> commandManager) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
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 String message = context.<String>getRequired("message").replace("</pre>", "");
|
||||
|
||||
+2
-2
@@ -12,7 +12,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class MessageCommand {
|
||||
|
||||
public MessageCommand(@NonNull final CommandManager<ChatUser> commandManager) {
|
||||
public MessageCommand(final @NonNull CommandManager<ChatUser> commandManager) {
|
||||
final CarbonChat carbonChat = CarbonChatProvider.carbonChat();
|
||||
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")
|
||||
.sendMessage(context.getSender(), context.getRequired("message"));
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ public class MuteCommand {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public MuteCommand(@NonNull final CommandManager<ChatUser> commandManager) {
|
||||
public MuteCommand(final @NonNull CommandManager<ChatUser> commandManager) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
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 target = context.getRequired("user");
|
||||
|
||||
|
||||
+3
-3
@@ -15,7 +15,7 @@ public class NicknameCommand {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public NicknameCommand(@NonNull final CommandManager<ChatUser> commandManager) {
|
||||
public NicknameCommand(final @NonNull CommandManager<ChatUser> commandManager) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
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();
|
||||
String nickname = context.getRequired("nickname");
|
||||
|
||||
@@ -70,7 +70,7 @@ public class NicknameCommand {
|
||||
"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");
|
||||
String nickname = context.getRequired("nickname");
|
||||
|
||||
|
||||
+2
-2
@@ -15,7 +15,7 @@ public class ReplyCommand {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public ReplyCommand(@NonNull final CommandManager<ChatUser> commandManager) {
|
||||
public ReplyCommand(final @NonNull CommandManager<ChatUser> commandManager) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
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 String input = context.getRequired("message");
|
||||
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ public class SetColorCommand {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public SetColorCommand(@NonNull final CommandManager<ChatUser> commandManager) {
|
||||
public SetColorCommand(final @NonNull CommandManager<ChatUser> commandManager) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
final CommandSettings commandSettings = this.carbonChat.commandSettingsRegistry().get("setcolor");
|
||||
|
||||
+2
-2
@@ -15,7 +15,7 @@ public class ShadowMuteCommand {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public ShadowMuteCommand(@NonNull final CommandManager<ChatUser> commandManager) {
|
||||
public ShadowMuteCommand(final @NonNull CommandManager<ChatUser> commandManager) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
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 target = context.getRequired("user");
|
||||
|
||||
|
||||
+4
-4
@@ -18,7 +18,7 @@ public class SpyChannelCommand {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public SpyChannelCommand(@NonNull final CommandManager<ChatUser> commandManager) {
|
||||
public SpyChannelCommand(final @NonNull CommandManager<ChatUser> commandManager) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
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 ChatChannel chatChannel = context.getRequired("channel");
|
||||
|
||||
@@ -79,7 +79,7 @@ public class SpyChannelCommand {
|
||||
"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 String message;
|
||||
@@ -95,7 +95,7 @@ public class SpyChannelCommand {
|
||||
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 Boolean shouldSpy = context.getRequired("enabled");
|
||||
|
||||
|
||||
+3
-3
@@ -17,7 +17,7 @@ public class SudoChannelCommand {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public SudoChannelCommand(@NonNull final CommandManager<ChatUser> commandManager) {
|
||||
public SudoChannelCommand(final @NonNull CommandManager<ChatUser> commandManager) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
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 user = context.getRequired("user");
|
||||
final ChatChannel channel = context.getRequired("channel");
|
||||
@@ -69,7 +69,7 @@ public class SudoChannelCommand {
|
||||
"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 ChatChannel channel = context.getRequired("channel");
|
||||
final String message = context.getRequired("message");
|
||||
|
||||
+3
-3
@@ -16,7 +16,7 @@ public class ToggleCommand {
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public ToggleCommand(@NonNull final CommandManager<ChatUser> commandManager) {
|
||||
public ToggleCommand(final @NonNull CommandManager<ChatUser> commandManager) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
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 ChatChannel channel = context.getRequired("channel");
|
||||
|
||||
@@ -69,7 +69,7 @@ public class ToggleCommand {
|
||||
"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 user = context.getRequired("user");
|
||||
final ChatChannel channel = context.getRequired("channel");
|
||||
|
||||
+4
-4
@@ -13,22 +13,22 @@ import java.util.function.Consumer;
|
||||
public class EmptyMessageService implements MessageService {
|
||||
|
||||
@Override
|
||||
public void registerUserMessageListener(@NonNull final String key, @NonNull final BiConsumer<@NonNull ChatUser, @NonNull ByteArrayDataInput> listener) {
|
||||
public void registerUserMessageListener(final @NonNull String key, final @NonNull BiConsumer<@NonNull ChatUser, @NonNull ByteArrayDataInput> listener) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@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
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterMessageListener(@NonNull final String key) {
|
||||
public void unregisterMessageListener(final @NonNull String key) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@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
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -24,7 +24,7 @@ public class MessageManager {
|
||||
@NonNull
|
||||
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.messageService = messageService;
|
||||
this.gsonSerializer = this.carbonChat.messageProcessor().audiences().gsonSerializer();
|
||||
@@ -123,8 +123,8 @@ public class MessageManager {
|
||||
return this.messageService;
|
||||
}
|
||||
|
||||
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) {
|
||||
this.messageService().sendMessage(key, uuid, consumer);
|
||||
}
|
||||
|
||||
|
||||
+5
-5
@@ -10,23 +10,23 @@ public interface RedisListener extends RedisPubSubListener<String, String> {
|
||||
void message(@NonNull String channel, @NonNull String message);
|
||||
|
||||
@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
|
||||
default void subscribed(@NonNull final String channel, final long count) {
|
||||
default void subscribed(final @NonNull String channel, final long count) {
|
||||
}
|
||||
|
||||
@Override
|
||||
default void psubscribed(@NonNull final String pattern, final long count) {
|
||||
default void psubscribed(final @NonNull String pattern, final long count) {
|
||||
}
|
||||
|
||||
@Override
|
||||
default void unsubscribed(@NonNull final String channel, final long count) {
|
||||
default void unsubscribed(final @NonNull String channel, final long count) {
|
||||
}
|
||||
|
||||
@Override
|
||||
default void punsubscribed(@NonNull final String pattern, final long count) {
|
||||
default void punsubscribed(final @NonNull String pattern, final long count) {
|
||||
}
|
||||
|
||||
}
|
||||
+7
-6
@@ -10,6 +10,7 @@ import io.lettuce.core.pubsub.api.sync.RedisPubSubCommands;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.messaging.MessageService;
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
import net.draycia.carbon.common.utils.RedisCredentials;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.Base64;
|
||||
@@ -39,7 +40,7 @@ public class RedisMessageService implements MessageService {
|
||||
@NonNull
|
||||
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;
|
||||
|
||||
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);
|
||||
|
||||
if (user != null) {
|
||||
@@ -91,19 +92,19 @@ public class RedisMessageService implements MessageService {
|
||||
}
|
||||
|
||||
@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.subscribeSync.subscribe(key);
|
||||
}
|
||||
|
||||
@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.subscribeSync.subscribe(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterMessageListener(@NonNull final String key) {
|
||||
public void unregisterMessageListener(final @NonNull String key) {
|
||||
this.userLoadedListeners.remove(key);
|
||||
this.userNotLoadedListeners.remove(key);
|
||||
|
||||
@@ -111,7 +112,7 @@ public class RedisMessageService implements MessageService {
|
||||
}
|
||||
|
||||
@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();
|
||||
|
||||
msg.writeLong(this.serverUUID.getMostSignificantBits());
|
||||
|
||||
+12
-11
@@ -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 Type userType;
|
||||
private final @NonNull Supplier<@NonNull Iterable<@NonNull T>> supplier;
|
||||
|
||||
private final @NonNull LoadingCache<@NonNull UUID, @NonNull T> userCache = CacheBuilder.newBuilder()
|
||||
.removalListener(this::saveUser)
|
||||
.build(CacheLoader.from(this::loadUser));
|
||||
|
||||
public JSONUserService(@NonNull final Class<? extends ChatUser> userType,
|
||||
@NonNull final CarbonChat carbonChat,
|
||||
@NonNull final Supplier<@NonNull Iterable<@NonNull T>> supplier) {
|
||||
public JSONUserService(final @NonNull Class<? extends ChatUser> userType,
|
||||
final @NonNull CarbonChat carbonChat,
|
||||
final @NonNull Supplier<@NonNull Iterable<@NonNull T>> supplier) {
|
||||
this.userType = userType;
|
||||
this.carbonChat = carbonChat;
|
||||
this.supplier = supplier;
|
||||
@@ -61,7 +62,7 @@ public class JSONUserService<T extends ChatUser> implements UserService<T> {
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public T wrap(@NonNull final UUID uuid) {
|
||||
public T wrap(final @NonNull UUID uuid) {
|
||||
try {
|
||||
return this.userCache.get(uuid);
|
||||
} catch (final ExecutionException exception) {
|
||||
@@ -72,25 +73,25 @@ public class JSONUserService<T extends ChatUser> implements UserService<T> {
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public T wrapIfLoaded(@NonNull final UUID uuid) {
|
||||
public T wrapIfLoaded(final @NonNull UUID uuid) {
|
||||
return this.userCache.getIfPresent(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public T refreshUser(@NonNull final UUID uuid) {
|
||||
public T refreshUser(final @NonNull UUID uuid) {
|
||||
this.userCache.invalidate(uuid);
|
||||
|
||||
return this.wrap(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate(@NonNull final T user) {
|
||||
public void invalidate(final @NonNull T user) {
|
||||
this.userCache.invalidate(user.uuid());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate(@NonNull final T user) {
|
||||
public void validate(final @NonNull T user) {
|
||||
this.userCache.put(user.uuid(), user);
|
||||
}
|
||||
|
||||
@@ -100,7 +101,7 @@ public class JSONUserService<T extends ChatUser> implements UserService<T> {
|
||||
}
|
||||
|
||||
@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");
|
||||
this.ensureFileExists(userFile);
|
||||
|
||||
@@ -123,7 +124,7 @@ public class JSONUserService<T extends ChatUser> implements UserService<T> {
|
||||
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");
|
||||
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()) {
|
||||
file.getParentFile().mkdirs();
|
||||
}
|
||||
|
||||
+63
-36
@@ -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.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.users.UserChannelSettings;
|
||||
import co.aikar.idb.BukkitDB;
|
||||
import co.aikar.idb.DB;
|
||||
import co.aikar.idb.Database;
|
||||
import co.aikar.idb.DbRow;
|
||||
import co.aikar.idb.DbStatement;
|
||||
import co.aikar.idb.HikariPooledDatabase;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.cache.RemovalNotification;
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
import net.draycia.carbon.api.users.UserService;
|
||||
import net.draycia.carbon.common.utils.SQLCredentials;
|
||||
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.Nullable;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.SQLSyntaxErrorException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.UUID;
|
||||
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 CarbonChat carbonChat;
|
||||
@NonNull
|
||||
private final Database database;
|
||||
@NonNull
|
||||
private final LoadingCache<@NonNull UUID, @NonNull BukkitChatUser> userCache = CacheBuilder.newBuilder()
|
||||
private final @NonNull CarbonChat carbonChat;
|
||||
private final @NonNull Database database;
|
||||
private final @NonNull Type userType;
|
||||
private final @NonNull Supplier<@NonNull Iterable<@NonNull T>> supplier;
|
||||
|
||||
private final @NonNull LoadingCache<@NonNull UUID, @NonNull T> userCache = CacheBuilder.newBuilder()
|
||||
.removalListener(this::saveUser)
|
||||
.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.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) {
|
||||
throw new IllegalStateException("Missing Database Credentials!");
|
||||
}
|
||||
final String hostAndPort = host + ":" + port;
|
||||
|
||||
final String username = section.getString("username", "username");
|
||||
final String password = section.getString("password", "password");
|
||||
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));
|
||||
final DatabaseOptions options = DatabaseOptions.builder().mysql(username, password, database, hostAndPort).build();
|
||||
this.database = PooledDatabaseOptions.builder().options(options).createHikariDatabase();
|
||||
|
||||
DB.setGlobalDatabase(this.database);
|
||||
|
||||
@@ -74,6 +81,15 @@ public class MySQLUserService implements UserService {
|
||||
} catch (final SQLException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
||||
final TimerTask timerTask = new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
MySQLUserService.this.userCache.cleanUp();
|
||||
}
|
||||
};
|
||||
|
||||
new Timer().schedule(timerTask, 0L, 300000L);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -85,7 +101,7 @@ public class MySQLUserService implements UserService {
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ChatUser wrap(@NonNull final UUID uuid) {
|
||||
public T wrap(final @NonNull UUID uuid) {
|
||||
try {
|
||||
return this.userCache.get(uuid);
|
||||
} catch (final ExecutionException exception) {
|
||||
@@ -96,31 +112,42 @@ public class MySQLUserService implements UserService {
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ChatUser wrapIfLoaded(@NonNull final UUID uuid) {
|
||||
public T wrapIfLoaded(final @NonNull UUID uuid) {
|
||||
return this.userCache.getIfPresent(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ChatUser refreshUser(@NonNull final UUID uuid) {
|
||||
public T refreshUser(final @NonNull UUID uuid) {
|
||||
this.userCache.invalidate(uuid);
|
||||
|
||||
return this.wrap(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate(@NonNull final ChatUser user) {
|
||||
public void invalidate(final @NonNull T user) {
|
||||
this.userCache.invalidate(user.uuid());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate(@NonNull final ChatUser user) {
|
||||
this.userCache.put(user.uuid(), (BukkitChatUser) user);
|
||||
public void validate(final @NonNull T user) {
|
||||
this.userCache.put(user.uuid(), user);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private BukkitChatUser loadUser(@NonNull final UUID uuid) {
|
||||
final BukkitChatUser user = new BukkitChatUser(uuid);
|
||||
@Override
|
||||
public @NonNull Iterable<@NonNull T> onlineUsers() {
|
||||
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 = ?;")) {
|
||||
statement.execute(uuid.toString());
|
||||
@@ -177,8 +204,8 @@ public class MySQLUserService implements UserService {
|
||||
return user;
|
||||
}
|
||||
|
||||
private void saveUser(@NonNull final RemovalNotification<@NonNull UUID, @NonNull BukkitChatUser> notification) {
|
||||
final BukkitChatUser user = notification.getValue();
|
||||
private void saveUser(final @NonNull RemovalNotification<@NonNull UUID, @NonNull T> notification) {
|
||||
final T user = notification.getValue();
|
||||
|
||||
this.database.createTransaction(stm -> {
|
||||
// Save user general data
|
||||
@@ -188,13 +215,13 @@ public class MySQLUserService implements UserService {
|
||||
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 (?, ?, ?, ?, ?, ?) " +
|
||||
"ON DUPLICATE KEY UPDATE channel = ?, muted = ?, shadowmuted = ?, spyingwhispers = ?, nickname =?",
|
||||
user.uuid().toString(), 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
|
||||
for (final Map.Entry<String, ? extends UserChannelSettings> entry : user.channelSettings().entrySet()) {
|
||||
final UserChannelSettings value = entry.getValue();
|
||||
@@ -211,7 +238,7 @@ public class MySQLUserService implements UserService {
|
||||
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)
|
||||
// TODO: keep DB up to date with settings as settings are mutated
|
||||
stm.executeUpdateQuery("DELETE FROM sc_ignored_users WHERE uuid = ?", user.uuid().toString());
|
||||
+1
-1
@@ -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.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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user