mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-03 22:15:45 +00:00
things
This commit is contained in:
1 parent
e263bccbfc
commit
8db4b9532c
63 files changed
+632
-472
No files matched your search
@@ -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;
|
||||
}
|
||||
|
||||
-228
@@ -1,228 +0,0 @@
|
||||
package net.draycia.carbon.storage.impl;
|
||||
|
||||
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.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.sql.SQLException;
|
||||
import java.sql.SQLSyntaxErrorException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public class MySQLUserService implements UserService {
|
||||
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
@NonNull
|
||||
private final Database database;
|
||||
@NonNull
|
||||
private final LoadingCache<@NonNull UUID, @NonNull BukkitChatUser> userCache = CacheBuilder.newBuilder()
|
||||
.removalListener(this::saveUser)
|
||||
.build(CacheLoader.from(this::loadUser));
|
||||
|
||||
public MySQLUserService(@NonNull final CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
final ConfigurationSection section = this.carbonChat.getConfig().getConfigurationSection("storage");
|
||||
|
||||
if (section == null) {
|
||||
throw new IllegalStateException("Missing Database Credentials!");
|
||||
}
|
||||
|
||||
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));
|
||||
|
||||
DB.setGlobalDatabase(this.database);
|
||||
|
||||
try {
|
||||
this.database.executeUpdate("CREATE TABLE IF NOT EXISTS sc_users (uuid CHAR(36) PRIMARY KEY," +
|
||||
"channel VARCHAR(16), muted BOOLEAN, shadowmuted BOOLEAN, spyingwhispers BOOLEAN," +
|
||||
"nickname VARCHAR(512))");
|
||||
|
||||
// Ignore the exception, it's just saying the column already exists
|
||||
try {
|
||||
this.database.executeUpdate("ALTER TABLE sc_users ADD COLUMN spyingwhispers BOOLEAN DEFAULT false");
|
||||
this.database.executeUpdate("ALTER TABLE sc_users ADD COLUMN nickname VARCHAR(512) DEFAULT false");
|
||||
} catch (final SQLSyntaxErrorException ignored) {
|
||||
}
|
||||
|
||||
this.database.executeUpdate("CREATE TABLE IF NOT EXISTS sc_channel_settings (uuid CHAR(36), channel CHAR(16), spying BOOLEAN, ignored BOOLEAN, color TINYTEXT, PRIMARY KEY (uuid, channel))");
|
||||
|
||||
this.database.executeUpdate("CREATE TABLE IF NOT EXISTS sc_ignored_users (uuid CHAR(36), user CHAR(36), PRIMARY KEY (uuid, user))");
|
||||
} catch (final SQLException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
this.userCache.invalidateAll();
|
||||
this.userCache.cleanUp();
|
||||
this.database.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ChatUser wrap(@NonNull final UUID uuid) {
|
||||
try {
|
||||
return this.userCache.get(uuid);
|
||||
} catch (final ExecutionException exception) {
|
||||
exception.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ChatUser wrapIfLoaded(@NonNull final UUID uuid) {
|
||||
return this.userCache.getIfPresent(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ChatUser refreshUser(@NonNull final UUID uuid) {
|
||||
this.userCache.invalidate(uuid);
|
||||
|
||||
return this.wrap(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate(@NonNull final ChatUser user) {
|
||||
this.userCache.invalidate(user.uuid());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate(@NonNull final ChatUser user) {
|
||||
this.userCache.put(user.uuid(), (BukkitChatUser) user);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private BukkitChatUser loadUser(@NonNull final UUID uuid) {
|
||||
final BukkitChatUser user = new BukkitChatUser(uuid);
|
||||
|
||||
try (final DbStatement statement = this.database.query("SELECT * from sc_users WHERE uuid = ?;")) {
|
||||
statement.execute(uuid.toString());
|
||||
|
||||
final DbRow users = statement.getNextRow();
|
||||
|
||||
if (users == null) {
|
||||
return user;
|
||||
}
|
||||
|
||||
final List<DbRow> channelSettings = this.database.getResults("SELECT * from sc_channel_settings WHERE uuid = ?;", uuid.toString());
|
||||
final List<DbRow> ignoredUsers = this.database.getResults("SELECT * from sc_ignored_users WHERE uuid = ?;", uuid.toString());
|
||||
|
||||
final ChatChannel channel = this.carbonChat.channelRegistry().channelOrDefault(users.getString("channel"));
|
||||
|
||||
if (channel != null) {
|
||||
user.selectedChannel(channel, true);
|
||||
}
|
||||
|
||||
final String nickname = users.getString("nickname");
|
||||
|
||||
if (nickname != null) {
|
||||
user.nickname(nickname, true);
|
||||
}
|
||||
|
||||
user.muted(users.<Boolean>get("muted"), true);
|
||||
user.shadowMuted(users.<Boolean>get("shadowmuted"), true);
|
||||
user.spyingWhispers(users.<Boolean>get("spyingwhispers"), true);
|
||||
|
||||
for (final DbRow channelSetting : channelSettings) {
|
||||
final ChatChannel chatChannel = this.carbonChat.channelRegistry().get(channelSetting.getString("channel"));
|
||||
|
||||
if (chatChannel != null) {
|
||||
final UserChannelSettings settings = user.channelSettings(chatChannel);
|
||||
|
||||
settings.spying(channelSetting.<Boolean>get("spying"), true);
|
||||
settings.ignoring(channelSetting.<Boolean>get("ignored"), true);
|
||||
|
||||
final String color = channelSetting.getString("color");
|
||||
|
||||
if (color != null) {
|
||||
settings.color(TextColor.fromHexString(color), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (final DbRow ignoredUser : ignoredUsers) {
|
||||
user.ignoringUser(UUID.fromString(ignoredUser.getString("user")), true, true);
|
||||
}
|
||||
} catch (final SQLException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
private void saveUser(@NonNull final RemovalNotification<@NonNull UUID, @NonNull BukkitChatUser> notification) {
|
||||
final BukkitChatUser user = notification.getValue();
|
||||
|
||||
this.database.createTransaction(stm -> {
|
||||
// Save user general data
|
||||
String selectedName = null;
|
||||
|
||||
if (user.selectedChannel() != null) {
|
||||
selectedName = user.selectedChannel().key();
|
||||
}
|
||||
|
||||
this.carbonChat.getLogger().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!");
|
||||
// Save user channel settings
|
||||
for (final Map.Entry<String, ? extends UserChannelSettings> entry : user.channelSettings().entrySet()) {
|
||||
final UserChannelSettings value = entry.getValue();
|
||||
|
||||
String colorString = null;
|
||||
|
||||
if (value.color() != null) {
|
||||
colorString = value.color().asHexString();
|
||||
}
|
||||
|
||||
stm.executeUpdateQuery("INSERT INTO sc_channel_settings (uuid, channel, spying, ignored, color) VALUES (?, ?, ?, ?, ?) " +
|
||||
"ON DUPLICATE KEY UPDATE spying = ?, ignored = ?, color = ?",
|
||||
user.uuid().toString(), entry.getKey(), value.spying(), value.ignored(), colorString,
|
||||
value.spying(), value.ignored(), colorString);
|
||||
}
|
||||
|
||||
this.carbonChat.getLogger().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());
|
||||
|
||||
for (final UUID entry : user.ignoredUsers()) {
|
||||
stm.executeUpdateQuery("INSERT INTO sc_ignored_users (uuid, user) VALUES (?, ?)",
|
||||
user.uuid().toString(), entry.toString());
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
+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;
|
||||
|
||||
Reference in new issue
Block a user