Progress on CarbonChat-Common

This commit is contained in:
Draycia committed 2020-09-25 01:44:39 -07:00
1 parent 508ad88e26
commit 64295c84ea
60 files changed
+889 -556

No files matched your search

+3 -23
View File
@@ -1,37 +1,17 @@
plugins {
id 'java'
id 'checkstyle'
}
description 'CarbonChat-API'
repositories {
mavenLocal()
mavenCentral()
maven { url = 'https://repo.maven.apache.org/maven2' }
maven { url = 'https://oss.sonatype.org/content/groups/public/' }
maven { url = 'https://repo.minebench.de/' }
}
dependencies {
checkstyle("ca.stellardrift:stylecheck:0.1-SNAPSHOT")
compile("org.checkerframework:checker-qual:3.6.1")
compile 'org.checkerframework:checker-qual:3.6.1'
compile 'net.kyori:adventure-api:4.0.0-SNAPSHOT'
compile 'net.kyori:adventure-nbt:4.0.0-SNAPSHOT'
compile 'net.kyori:adventure-platform-bukkit:4.0.0-SNAPSHOT'
compile 'net.kyori:adventure-text-minimessage:4.0.0-SNAPSHOT'
compile 'de.themoep:minedown-adventure:1.6.1-SNAPSHOT'
compile 'net.kyori:event-api:3.0.0'
compile 'net.kyori:registry:1.0.0-SNAPSHOT'
}
checkstyle {
def configRoot = new File(rootProject.projectDir, '.checkstyle')
toolVersion = '8.34'
configDirectory = configRoot
configProperties = [basedir: configRoot.getAbsolutePath()]
compileOnly 'org.spongepowered:configurate-yaml:4.0.0-SNAPSHOT'
}
@@ -1,4 +1,22 @@
package net.draycia.carbon.api;
public class CarbonChat {
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.CommandSettingsRegistry;
import net.draycia.carbon.api.users.UserService;
import org.checkerframework.checker.nullness.qual.NonNull;
public interface CarbonChat {
@NonNull UserService userService();
@NonNull MessageProcessor messageProcessor();
@NonNull ChannelRegistry channelRegistry();
@NonNull CommandSettingsRegistry commandSettingsRegistry();
@NonNull CarbonTranslations translations();
}
@@ -0,0 +1,201 @@
package net.draycia.carbon.api.adventure;
import org.spongepowered.configurate.BasicConfigurationNode;
import org.spongepowered.configurate.objectmapping.ObjectMapper;
import org.spongepowered.configurate.objectmapping.ObjectMappingException;
import org.spongepowered.configurate.objectmapping.Setting;
import org.spongepowered.configurate.serialize.ConfigSerializable;
@ConfigSerializable
public class CarbonTranslations {
private static final ObjectMapper<CarbonTranslations> MAPPER;
static {
try {
MAPPER = ObjectMapper.forClass(CarbonTranslations.class); // We hold on to the instance of our ObjectMapper
} catch (final ObjectMappingException e) {
throw new ExceptionInInitializerError(e);
}
}
public static CarbonTranslations loadFrom(final BasicConfigurationNode node) throws ObjectMappingException {
return MAPPER.bindToNew().populate(node);
}
public void saveTo(final BasicConfigurationNode node) throws ObjectMappingException {
MAPPER.bind(this).serialize(node);
}
@Setting private String reloaded = "<yellow>Chat config has been reloaded!";
@Setting private String messageToOther = "<green>[<gray>Me <gold>-> <gray><target><reset><green>] <message>";
@Setting private String messageFromOther = "<green>[<gray><sender><reset> <gold>-> <gray>Me<green>] <message>";
@Setting private String otherPlayerOffline = "<red>That player is offline!";
@Setting private String spyWhispers = "<yellow>Spy [<gray><sender><reset> <gold>-> <gray><target><reset><yellow>] <message>";
@Setting private String noReplyTarget = "<red>You have no one to reply to!";
@Setting private String otherNicknameSet = "<green><user><reset>''s nickname was set to <nickname><green>!";
@Setting private String otherNicknameReset = "<green><user><reset>'s nickname was reset!";
@Setting private String availableChannelsList = "<green>Available Channels:<reset> <list>.";
@Setting private String unavailableChannelsList = "<red>Unavailable Channels:<reset> <list>.";
@Setting private String channelListSeparator = ", ";
@Setting private String userMustBeOnline = "<red><player> must be online!";
@Setting private String replyMessageBlank = "<red>Your reply message was blank!";
@Setting private String invalidColor = "<red>The input <input> is not a valid color!";
@Setting private String cannotSetColor = "<red>You do not have permission to set a color for this channel!";
@Setting private String roleplayFormat = "<italic><dark_purple>*<displayname> <reset><message>*</dark_purple></italic>";
@Setting private String ignoringUser = "<green>You are now ignoring <gold><player><reset><green>!";
@Setting private String notIgnoringUser = "<green>You are no longer ignoring <gold><player><reset><green>!";
@Setting private String ignoreExempt = "<red>User <player> <red>is exempt from being ignored!";
@Setting private String channelColorSet = "<green>You have set <color><channel> <green>color to <hex>!";
@Setting private String spyToggledOn = "<gray>You are now spying on <color><channel> <gray>chat!";
@Setting private String spyToggledOff = "<gray>You are no longer spying on <color><channel> <gray>chat!";
@Setting private String spyWhispersOn = "<gray>You are now spying on whispers!";
@Setting private String spyWhispersOff = "<gray>You are no longer spying on whispers!";
@Setting private String nicknameSet = "<green>Your nickname was set to <nickname><reset><green>!";
@Setting private String nicknameReset = "<green>Your nickname was reset!";
@Setting private String nowShadowMuted = "<yellow>Player <player> is now shadow muted!";
@Setting private String noLongerShadowMuted = "<yellow>Player <player> is no longer shadow muted!";
@Setting private String shadowMuteExempt = "<red>Player <player> is exempt from being shadow muted!";
@Setting private String nowMuted = "<yellow>Player <player> is now muted!";
@Setting private String noLongerMuted = "<yellow>Player <player> is no longer muted!";
@Setting private String muteExempt = "<red>Player <player> is exempt from being muted!";
@Setting private String clearNotify = "<yellow>Chat has been cleared by <player>.";
@Setting private String clearExempt = "<yellow>You were exempt from the clear due to your permissions!";
public String reloaded() {
return this.reloaded;
}
public String messageToOther() {
return this.messageToOther;
}
public String messageFromOther() {
return this.messageFromOther;
}
public String otherPlayerOffline() {
return this.otherPlayerOffline;
}
public String spyWhispers() {
return this.spyWhispers;
}
public String noReplyTarget() {
return this.noReplyTarget;
}
public String otherNicknameSet() {
return this.otherNicknameSet;
}
public String otherNicknameReset() {
return this.otherNicknameReset;
}
public String availableChannelsList() {
return this.availableChannelsList;
}
public String unavailableChannelsList() {
return this.unavailableChannelsList;
}
public String channelListSeparator() {
return this.channelListSeparator;
}
public String userMustBeOnline() {
return this.userMustBeOnline;
}
public String replyMessageBlank() {
return this.replyMessageBlank;
}
public String invalidColor() {
return this.invalidColor;
}
public String cannotSetColor() {
return this.cannotSetColor;
}
public String roleplayFormat() {
return this.roleplayFormat;
}
public String ignoringUser() {
return this.ignoringUser;
}
public String notIgnoringUser() {
return this.notIgnoringUser;
}
public String ignoreExempt() {
return this.ignoreExempt;
}
public String channelColorSet() {
return this.channelColorSet;
}
public String spyToggledOn() {
return this.spyToggledOn;
}
public String spyToggledOff() {
return this.spyToggledOff;
}
public String spyWhispersOn() {
return this.spyWhispersOn;
}
public String spyWhispersOff() {
return this.spyWhispersOff;
}
public String nicknameSet() {
return this.nicknameSet;
}
public String nicknameReset() {
return this.nicknameReset;
}
public String nowShadowMuted() {
return this.nowShadowMuted;
}
public String noLongerShadowMuted() {
return this.noLongerShadowMuted;
}
public String shadowMuteExempt() {
return this.shadowMuteExempt;
}
public String nowMuted() {
return this.nowMuted;
}
public String noLongerMuted() {
return this.noLongerMuted;
}
public String muteExempt() {
return this.muteExempt;
}
public String clearNotify() {
return this.clearNotify;
}
public String clearExempt() {
return this.clearExempt;
}
}
@@ -0,0 +1,14 @@
package net.draycia.carbon.api.adventure;
import net.kyori.adventure.platform.AudienceProvider;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
public interface MessageProcessor {
@NonNull Component processMessage(@Nullable final String input, @NonNull final String @NonNull ... placeholders);
@NonNull AudienceProvider audiences();
}
@@ -14,10 +14,17 @@ public class ChannelRegistry implements Registry<String, ChatChannel> {
@NonNull
private final Map<@NonNull String, @NonNull ChatChannel> registry = new HashMap<>();
@Nullable
private ChatChannel defaultChannel = null;
@Override
public @NonNull ChatChannel register(@NonNull final String key, @NonNull final ChatChannel value) {
this.registry.putIfAbsent(key, value);
if (this.defaultChannel == null && value.isDefault()) {
this.defaultChannel = value;
}
return value;
}
@@ -26,6 +33,10 @@ public class ChannelRegistry implements Registry<String, ChatChannel> {
return this.registry.get(key);
}
public @Nullable ChatChannel channelOrDefault(@NonNull final String key) {
return this.registry.getOrDefault(key, this.defaultChannel());
}
@Override
public @Nullable String key(@NonNull final ChatChannel value) {
return null;
@@ -40,4 +51,9 @@ public class ChannelRegistry implements Registry<String, ChatChannel> {
public @NonNull Iterator<ChatChannel> iterator() {
return this.registry.values().iterator();
}
public @Nullable ChatChannel defaultChannel() {
return this.defaultChannel;
}
}
@@ -1,18 +1,22 @@
package net.draycia.carbon.api.commands;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.spongepowered.configurate.objectmapping.Setting;
import org.spongepowered.configurate.serialize.ConfigSerializable;
import java.util.List;
@ConfigSerializable
public class CommandSettings {
@Setting
private final boolean enabled;
@NonNull
private final String name;
@Setting
private @NonNull final String name;
@NonNull
private final List<@NonNull String> aliases;
@Setting
private @NonNull final List<@NonNull String> aliases;
public CommandSettings(final boolean enabled, @NonNull final String name, @NonNull final List<@NonNull String> aliases) {
this.enabled = enabled;
@@ -0,0 +1,73 @@
package net.draycia.carbon.api.commands;
import net.draycia.carbon.api.channels.ChatChannel;
import net.kyori.registry.Registry;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.spongepowered.configurate.BasicConfigurationNode;
import org.spongepowered.configurate.objectmapping.ObjectMapper;
import org.spongepowered.configurate.objectmapping.ObjectMappingException;
import org.spongepowered.configurate.objectmapping.Setting;
import org.spongepowered.configurate.serialize.ConfigSerializable;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
@ConfigSerializable
public class CommandSettingsRegistry implements Registry<String, CommandSettings> {
private static final ObjectMapper<CommandSettingsRegistry> MAPPER;
static {
try {
MAPPER = ObjectMapper.forClass(CommandSettingsRegistry.class); // We hold on to the instance of our ObjectMapper
} catch (final ObjectMappingException e) {
throw new ExceptionInInitializerError(e);
}
}
public static CommandSettingsRegistry loadFrom(final BasicConfigurationNode node) throws ObjectMappingException {
return MAPPER.bindToNew().populate(node);
}
public void saveTo(final BasicConfigurationNode node) throws ObjectMappingException {
MAPPER.bind(this).serialize(node);
}
@Setting
private @NonNull final Map<@NonNull String, @NonNull CommandSettings> registry = new HashMap<>();
@Override
public @NonNull CommandSettings register(@NonNull final String key, @NonNull final CommandSettings value) {
this.registry.put(key, value);
return value;
}
@Override
public @Nullable CommandSettings get(@NonNull final String key) {
return this.registry.get(key);
}
public @Nullable CommandSettings get(@NonNull final ChatChannel channel) {
return this.get(channel.key());
}
@Override
public @Nullable String key(@NonNull final CommandSettings value) {
return null;
}
@Override
public @NonNull Set<String> keySet() {
return this.registry.keySet();
}
@Override
public @NonNull Iterator<CommandSettings> iterator() {
return this.registry.values().iterator();
}
}
+2 -27
View File
@@ -1,36 +1,14 @@
plugins {
id 'checkstyle'
id 'java'
id 'java-library'
id 'maven'
id 'maven-publish'
id 'com.github.johnrengelman.shadow' version '6.0.0'
id 'net.minecrell.plugin-yml.bukkit' version '0.3.0'
}
description = 'CarbonChat-Bukkit'
repositories {
mavenLocal()
mavenCentral()
maven { url = 'https://maven.enginehub.org/repo/' }
maven { url = 'https://repo.maven.apache.org/maven2' }
maven { url = 'https://papermc.io/repo/repository/maven-public/' }
maven { url = 'https://oss.sonatype.org/content/groups/public/' }
maven { url = 'https://repo.extendedclip.com/content/repositories/placeholderapi/' }
maven { url = 'https://jitpack.io' }
maven { url = 'https://repo.minebench.de/' }
maven { url = 'https://dl.bintray.com/ichbinjoe/public/' }
maven { url = 'https://repo.codemc.org/repository/maven-public/' }
maven { url = "https://repo.aikar.co/content/groups/aikar/" }
maven { url = 'https://raw.githubusercontent.com/JorelAli/CommandAPI/mvn-repo/' }
}
dependencies {
checkstyle("ca.stellardrift:stylecheck:0.1-SNAPSHOT")
compile 'org.spongepowered:configurate-yaml:4.0.0-SNAPSHOT'
compile project(":CarbonChat-API")
compile project(":CarbonChat-Common")
// Databases
compile 'co.aikar:idb-bukkit:1.0.0-SNAPSHOT'
@@ -38,9 +16,6 @@ dependencies {
// Messaging
compile 'io.github.leonardosnt:bungeechannelapi:1.0.0-SNAPSHOT'
compile('io.lettuce:lettuce-core:6.0.0.M1') {
exclude group: 'io.netty'
}
// Commands
compile "dev.jorel:commandapi-shade:4.2"
@@ -1,5 +1,12 @@
package net.draycia.carbon;
import net.draycia.carbon.api.CarbonChat;
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.CommandSettingsRegistry;
import net.draycia.carbon.common.adventure.FormatType;
import net.draycia.carbon.common.messaging.EmptyMessageService;
import net.draycia.carbon.listeners.contexts.DistanceContext;
import net.draycia.carbon.listeners.contexts.EconomyContext;
import net.draycia.carbon.listeners.contexts.FilterContext;
@@ -22,10 +29,9 @@ import net.draycia.carbon.listeners.events.ShadowMuteHandler;
import net.draycia.carbon.listeners.events.UrlLinkHandler;
import net.draycia.carbon.listeners.events.UserFormattingHandler;
import net.draycia.carbon.listeners.events.WhisperPingHandler;
import net.draycia.carbon.managers.AdventureManager;
import net.draycia.carbon.managers.ChannelManager;
import net.draycia.carbon.common.adventure.AdventureManager;
import net.draycia.carbon.managers.CommandManager;
import net.draycia.carbon.messaging.MessageManager;
import net.draycia.carbon.common.messaging.MessageManager;
import net.draycia.carbon.api.users.UserService;
import net.draycia.carbon.storage.impl.JSONUserService;
import net.draycia.carbon.storage.impl.MySQLUserService;
@@ -33,36 +39,40 @@ import net.draycia.carbon.util.CarbonPlaceholders;
import net.draycia.carbon.util.FunctionalityConstants;
import net.draycia.carbon.util.Metrics;
import dev.jorel.commandapi.CommandAPI;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.checkerframework.checker.nullness.qual.NonNull;
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;
public final class CarbonChat extends JavaPlugin {
public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
private static final int BSTATS_PLUGIN_ID = 8720;
private Permission permission;
private CommandManager commandManager;
private ChannelManager channelManager;
private AdventureManager adventureManager;
private ChannelRegistry channelRegistry;
private CommandSettingsRegistry commandSettings;
private AdventureManager messageProcessor;
private UserService userService;
private MessageManager messageManager;
private YamlConfiguration modConfig;
private YamlConfiguration languageConfig;
private YamlConfiguration commandsConfig;
private FilterContext filterContext;
private CarbonTranslations translations;
public static final LegacyComponentSerializer LEGACY =
LegacyComponentSerializer.builder()
.extractUrls()
@@ -90,26 +100,17 @@ public final class CarbonChat extends JavaPlugin {
this.saveResource("moderation.yml", false);
}
if (!(new File(this.getDataFolder(), "language.yml").exists())) {
this.saveResource("language.yml", false);
}
if (!(new File(this.getDataFolder(), "commands.yml").exists())) {
this.saveResource("commands.yml", false);
}
this.loadModConfig();
this.loadLanguage();
this.reloadConfig();
// Setup Adventure
this.adventureManager = new AdventureManager(this);
this.messageProcessor = new AdventureManager(BukkitAudiences.create(this), FormatType.MINIMESSAGE); // TODO: get format type from config
// Setup vault and permissions
this.permission = this.getServer().getServicesManager().getRegistration(Permission.class).getProvider();
// Initialize managers
this.channelManager = new ChannelManager(this);
this.messageManager = new MessageManager(this);
this.channelRegistry = new ChannelRegistry();
this.messageManager = new MessageManager(this, new EmptyMessageService()); // TODO: get message service from config
this.commandManager = new CommandManager(this);
final String storageType = this.getConfig().getString("storage.type");
@@ -169,25 +170,41 @@ public final class CarbonChat extends JavaPlugin {
this.loadModConfig();
this.loadLanguage();
this.loadCommandsConfig();
this.loadCommandSettings();
}
private void loadLanguage() {
final File languageFile = new File(this.getDataFolder(), "language.yml");
final YamlConfigurationLoader languageLoader = YamlConfigurationLoader.builder().setFile(languageFile).build();
try {
final BasicConfigurationNode languageNode = languageLoader.load();
this.translations = CarbonTranslations.loadFrom(languageNode);
languageLoader.save(languageNode);
} catch (final IOException | ObjectMappingException ignored) {
}
}
private void loadCommandSettings() {
if (!(new File(this.getDataFolder(), "carbon-commands.yml").exists())) {
this.saveResource("carbon-commands.yml", false);
}
final File commandSettingsFile = new File(this.getDataFolder(), "carbon-commands.yml");
final YamlConfigurationLoader commandSettingsLoader = YamlConfigurationLoader.builder().setFile(commandSettingsFile).build();
try {
final BasicConfigurationNode commandSettingsNode = commandSettingsLoader.load();
this.commandSettings = CommandSettingsRegistry.loadFrom(commandSettingsNode);
commandSettingsLoader.save(commandSettingsNode);
} catch (final IOException | ObjectMappingException ignored) {
}
}
public void reloadFilters() {
this.filterContext.reloadFilters();
}
private void loadModConfig() {
this.modConfig = YamlConfiguration.loadConfiguration(new File(this.getDataFolder(), "moderation.yml"));
}
private void loadLanguage() {
this.languageConfig = YamlConfiguration.loadConfiguration(new File(this.getDataFolder(), "language.yml"));
}
private void loadCommandsConfig() {
this.commandsConfig = YamlConfiguration.loadConfiguration(new File(this.getDataFolder(), "commands.yml"));
}
private void registerContexts() {
this.filterContext = new FilterContext(this);
@@ -210,21 +227,6 @@ public final class CarbonChat extends JavaPlugin {
new DistanceContext();
}
@NonNull
public YamlConfiguration moderationConfig() {
return this.modConfig;
}
@NonNull
public YamlConfiguration commandsConfig() {
return this.commandsConfig;
}
@NonNull
public YamlConfiguration language() {
return this.languageConfig;
}
@NonNull
public Permission permission() {
return this.permission;
@@ -235,11 +237,6 @@ public final class CarbonChat extends JavaPlugin {
return this.commandManager;
}
@NonNull
public ChannelManager channelManager() {
return this.channelManager;
}
@NonNull
public MessageManager messageManager() {
return this.messageManager;
@@ -250,8 +247,23 @@ public final class CarbonChat extends JavaPlugin {
return this.userService;
}
@NonNull
public AdventureManager adventureManager() {
return this.adventureManager;
@Override
public @NonNull ChannelRegistry channelRegistry() {
return this.channelRegistry;
}
@Override
public @NonNull CommandSettingsRegistry commandSettingsRegistry() {
return this.commandSettings;
}
@Override
public @NonNull CarbonTranslations translations() {
return this.translations;
}
@Override
public @NonNull MessageProcessor messageProcessor() {
return this.messageProcessor;
}
}
@@ -1,7 +1,7 @@
package net.draycia.carbon.channels;
import net.draycia.carbon.util.CarbonUtils;
import net.draycia.carbon.CarbonChat;
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;
@@ -35,19 +35,19 @@ public class CarbonChatChannel implements ChatChannel {
private final String key;
@NonNull
private final CarbonChat carbonChat;
private final CarbonChatBukkit carbonChat;
@Nullable
private final ConfigurationSection config;
public CarbonChatChannel(@NonNull final String key, @NonNull final CarbonChat carbonChat, @Nullable final ConfigurationSection config) {
public CarbonChatChannel(@NonNull final String key, @NonNull final CarbonChatBukkit carbonChat, @Nullable final ConfigurationSection config) {
this.key = key;
this.carbonChat = carbonChat;
this.config = config;
}
@NonNull
public CarbonChat carbonChat() {
public CarbonChatBukkit carbonChat() {
return this.carbonChat;
}
@@ -88,8 +88,8 @@ public class CarbonChatChannel implements ChatChannel {
String nickname = user.nickname();
if (nickname != null) {
final Component component = this.carbonChat.adventureManager().processMessage(nickname);
nickname = CarbonChat.LEGACY.serialize(component);
final Component component = this.carbonChat.messageProcessor().processMessage(nickname);
nickname = CarbonChatBukkit.LEGACY.serialize(component);
player.setDisplayName(nickname);
@@ -155,7 +155,7 @@ public class CarbonChatChannel implements ChatChannel {
final TextColor targetColor = this.channelColor(target);
TextComponent formatComponent = (TextComponent) this.carbonChat.adventureManager().processMessage(formatEvent.format(),
TextComponent formatComponent = (TextComponent) this.carbonChat.messageProcessor().processMessage(formatEvent.format(),
"br", "\n",
"displayname", displayName,
"color", "<" + targetColor.asHexString() + ">",
@@ -185,7 +185,7 @@ public class CarbonChatChannel implements ChatChannel {
final TextColor targetColor = this.channelColor(user);
final TextComponent consoleFormat = (TextComponent) this.carbonChat.adventureManager().processMessage(consoleFormatEvent.format(),
final TextComponent consoleFormat = (TextComponent) this.carbonChat.messageProcessor().processMessage(consoleFormatEvent.format(),
"br", "\n",
"displayname", displayName,
"color", "<" + targetColor.asHexString() + ">",
@@ -324,7 +324,7 @@ 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 -> {
byteArray.writeUTF(this.key());
byteArray.writeUTF(this.carbonChat.adventureManager().audiences().gsonSerializer().serialize(component));
byteArray.writeUTF(this.carbonChat.messageProcessor().audiences().gsonSerializer().serialize(component));
});
}
@@ -4,7 +4,7 @@ import dev.jorel.commandapi.CommandAPICommand;
import dev.jorel.commandapi.CommandPermission;
import dev.jorel.commandapi.arguments.Argument;
import dev.jorel.commandapi.arguments.GreedyStringArgument;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.CarbonChatBukkit;
import net.draycia.carbon.api.channels.ChatChannel;
import net.draycia.carbon.api.users.ChatUser;
import net.kyori.adventure.text.Component;
@@ -16,7 +16,7 @@ import java.util.LinkedHashMap;
public class AliasedChannelCommand {
@NonNull
private final CarbonChat carbonChat;
private final CarbonChatBukkit carbonChat;
@NonNull
private final ChatChannel chatChannel;
@@ -24,7 +24,7 @@ public class AliasedChannelCommand {
@NonNull
private final String commandName;
public AliasedChannelCommand(@NonNull final CarbonChat carbonChat, @NonNull final ChatChannel chatChannel) {
public AliasedChannelCommand(@NonNull final CarbonChatBukkit carbonChat, @NonNull final ChatChannel chatChannel) {
this.carbonChat = carbonChat;
this.chatChannel = chatChannel;
@@ -52,7 +52,7 @@ public class AliasedChannelCommand {
final ChatUser user = this.carbonChat.userService().wrap(player.getUniqueId());
if (user.channelSettings(this.chatChannel()).ignored()) {
user.sendMessage(this.carbonChat.adventureManager().processMessageWithPapi(player, this.chatChannel().cannotUseMessage(),
user.sendMessage(this.carbonChat.messageProcessor().processMessage(this.chatChannel().cannotUseMessage(),
"br", "\n",
"color", "<" + this.chatChannel().channelColor(user).toString() + ">",
"channel", this.chatChannel().name()));
@@ -69,7 +69,7 @@ public class AliasedChannelCommand {
final Component component = this.chatChannel().sendMessage(user, message, false);
this.carbonChat.adventureManager().audiences().console().sendMessage(component);
this.carbonChat.messageProcessor().audiences().console().sendMessage(component);
}
@NonNull
@@ -7,7 +7,7 @@ import dev.jorel.commandapi.CommandAPICommand;
import dev.jorel.commandapi.CommandPermission;
import dev.jorel.commandapi.arguments.Argument;
import dev.jorel.commandapi.arguments.GreedyStringArgument;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.CarbonChatBukkit;
import net.draycia.carbon.api.channels.ChatChannel;
import net.draycia.carbon.api.users.ChatUser;
import net.kyori.adventure.text.Component;
@@ -19,9 +19,9 @@ import java.util.LinkedHashMap;
public class ChannelCommand {
@NonNull
private final CarbonChat carbonChat;
private final CarbonChatBukkit carbonChat;
public ChannelCommand(@NonNull final CarbonChat carbonChat, @NonNull final CommandSettings commandSettings) {
public ChannelCommand(@NonNull final CarbonChatBukkit carbonChat, @NonNull final CommandSettings commandSettings) {
this.carbonChat = carbonChat;
if (!commandSettings.enabled()) {
@@ -57,7 +57,7 @@ public class ChannelCommand {
final ChatChannel channel = (ChatChannel) args[0];
if (user.channelSettings(channel).ignored()) {
user.sendMessage(this.carbonChat.adventureManager().processMessageWithPapi(player, channel.cannotUseMessage(),
user.sendMessage(this.carbonChat.messageProcessor().processMessage(channel.cannotUseMessage(),
"br", "\n",
"color", "<" + channel.channelColor(user).toString() + ">",
"channel", channel.name()));
@@ -75,7 +75,7 @@ public class ChannelCommand {
final Component component = channel.sendMessage(user, message, false);
this.carbonChat.adventureManager().audiences().console().sendMessage(component);
this.carbonChat.messageProcessor().audiences().console().sendMessage(component);
}
}
@@ -5,7 +5,7 @@ import net.draycia.carbon.util.CommandUtils;
import dev.jorel.commandapi.CommandAPICommand;
import dev.jorel.commandapi.CommandPermission;
import dev.jorel.commandapi.arguments.Argument;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.CarbonChatBukkit;
import net.draycia.carbon.api.channels.ChatChannel;
import net.draycia.carbon.api.users.ChatUser;
import net.draycia.carbon.api.commands.CommandSettings;
@@ -27,9 +27,9 @@ import java.util.regex.Pattern;
public class ChannelListCommand {
@NonNull
private final CarbonChat carbonChat;
private final CarbonChatBukkit carbonChat;
public ChannelListCommand(@NonNull final CarbonChat carbonChat, @NonNull final CommandSettings commandSettings) {
public ChannelListCommand(@NonNull final CarbonChatBukkit carbonChat, @NonNull final CommandSettings commandSettings) {
this.carbonChat = carbonChat;
if (!commandSettings.enabled()) {
@@ -59,25 +59,32 @@ public class ChannelListCommand {
}
public void executeSelf(@NonNull final Player player, @NonNull final Object @NonNull [] args) {
final Iterator<ChatChannel> allChannels = this.carbonChat.channelManager().registry().iterator();
final Iterator<ChatChannel> allChannels = this.carbonChat.channelRegistry().iterator();
final ChatUser user = this.carbonChat.userService().wrap(player.getUniqueId());
this.listAndSend(player, user, allChannels);
}
public void executeOther(@NonNull final CommandSender sender, @NonNull final Object @NonNull [] args) {
final Audience cmdSender = this.carbonChat.adventureManager().audiences().audience(sender);
final Audience cmdSender;
if (sender instanceof Player) {
cmdSender = this.carbonChat.userService().wrap(((Player) sender).getUniqueId());
} else {
cmdSender = this.carbonChat.messageProcessor().audiences().console();
}
final ChatUser user = (ChatUser) args[0];
final OfflinePlayer player = Bukkit.getOfflinePlayer(user.uuid());
if (!player.isOnline()) {
final String mustBeOnline = this.carbonChat.language().getString("user-must-be-online");
cmdSender.sendMessage(this.carbonChat.adventureManager().processMessage(mustBeOnline, "br", "\n", "player", player.getName()));
final String mustBeOnline = this.carbonChat.translations().userMustBeOnline();
cmdSender.sendMessage(this.carbonChat.messageProcessor().processMessage(mustBeOnline, "br", "\n", "player", player.getName()));
return;
}
final Iterator<ChatChannel> allChannels = this.carbonChat.channelManager().registry().iterator();
final Iterator<ChatChannel> allChannels = this.carbonChat.channelRegistry().iterator();
this.listAndSend(sender, user, allChannels);
}
@@ -102,13 +109,19 @@ public class ChannelListCommand {
this.makeList(visibleChannels, availableList);
final String availableFormat = this.carbonChat.language().getString("available-channels-list");
Component availableComponent = this.carbonChat.adventureManager().processMessage(availableFormat, "br", "\n");
final String availableFormat = this.carbonChat.translations().availableChannelsList();
Component availableComponent = this.carbonChat.messageProcessor().processMessage(availableFormat, "br", "\n");
availableComponent = availableComponent.replaceFirstText(Pattern.compile(Pattern.quote("<list>")), ac -> availableList);
final Audience audience = this.carbonChat.adventureManager().audiences().audience(sender);
final Audience cmdSender;
audience.sendMessage(availableComponent);
if (sender instanceof Player) {
cmdSender = this.carbonChat.userService().wrap(((Player) sender).getUniqueId());
} else {
cmdSender = this.carbonChat.messageProcessor().audiences().console();
}
cmdSender.sendMessage(availableComponent);
if (sender.hasPermission("carbonchat.channellist.bypass") && !cannotSee.isEmpty()) {
final Iterator<ChatChannel> invisibleChannels = cannotSee.iterator();
@@ -116,16 +129,16 @@ public class ChannelListCommand {
this.makeList(invisibleChannels, unavailableList);
final String unavailableFormat = this.carbonChat.language().getString("unavailable-channels-list");
Component unavailableComponent = this.carbonChat.adventureManager().processMessage(unavailableFormat, "br", "\n");
final String unavailableFormat = this.carbonChat.translations().unavailableChannelsList();
Component unavailableComponent = this.carbonChat.messageProcessor().processMessage(unavailableFormat, "br", "\n");
unavailableComponent = unavailableComponent.replaceFirstText(Pattern.compile(Pattern.quote("<list>")), uac -> unavailableList);
audience.sendMessage(unavailableComponent);
cmdSender.sendMessage(unavailableComponent);
}
}
private void makeList(@NonNull final Iterator<@NonNull ChatChannel> iterator, final TextComponent.@NonNull Builder list) {
final String listSeparator = this.carbonChat.language().getString("channel-list-separator", ", ");
final String listSeparator = this.carbonChat.translations().channelListSeparator();
// TODO: Larry, why did you double assign the listSeparatorComponent?
final Component listSeparatorComponent = TextComponent.of(listSeparator);
@@ -4,17 +4,19 @@ import net.draycia.carbon.api.commands.CommandSettings;
import net.draycia.carbon.util.CommandUtils;
import dev.jorel.commandapi.CommandAPICommand;
import dev.jorel.commandapi.CommandPermission;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.CarbonChatBukkit;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.checkerframework.checker.nullness.qual.NonNull;
public class ChatReloadCommand {
@NonNull
private final CarbonChat carbonChat;
private final CarbonChatBukkit carbonChat;
public ChatReloadCommand(@NonNull final CarbonChat carbonChat, @NonNull final CommandSettings commandSettings) {
public ChatReloadCommand(@NonNull final CarbonChatBukkit carbonChat, @NonNull final CommandSettings commandSettings) {
this.carbonChat = carbonChat;
if (!commandSettings.enabled()) {
@@ -34,10 +36,18 @@ public class ChatReloadCommand {
this.carbonChat.reloadConfig();
this.carbonChat.reloadFilters();
final Component message = this.carbonChat.adventureManager()
.processMessage(this.carbonChat.language().getString("reloaded"), "br", "\n");
final Component message = this.carbonChat.messageProcessor()
.processMessage(this.carbonChat.translations().reloaded().replace("br", "\n"));
this.carbonChat.adventureManager().audiences().audience(sender).sendMessage(message);
final Audience cmdSender;
if (sender instanceof Player) {
cmdSender = this.carbonChat.userService().wrap(((Player) sender).getUniqueId());
} else {
cmdSender = this.carbonChat.messageProcessor().audiences().console();
}
cmdSender.sendMessage(message);
}
}
@@ -5,7 +5,7 @@ import net.draycia.carbon.api.commands.CommandSettings;
import net.draycia.carbon.util.CommandUtils;
import dev.jorel.commandapi.CommandAPICommand;
import dev.jorel.commandapi.CommandPermission;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.CarbonChatBukkit;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
@@ -15,9 +15,9 @@ import org.checkerframework.checker.nullness.qual.NonNull;
public class ClearChatCommand {
@NonNull
private final CarbonChat carbonChat;
private final CarbonChatBukkit carbonChat;
public ClearChatCommand(@NonNull final CarbonChat carbonChat, @NonNull final CommandSettings commandSettings) {
public ClearChatCommand(@NonNull final CarbonChatBukkit carbonChat, @NonNull final CommandSettings commandSettings) {
this.carbonChat = carbonChat;
if (!commandSettings.enabled()) {
@@ -35,14 +35,14 @@ public class ClearChatCommand {
private void execute(@NonNull final CommandSender sender, @NonNull final Object @NonNull [] args) {
final String format = this.carbonChat.moderationConfig().getString("clear-chat.message", "");
final Component component = this.carbonChat.adventureManager().processMessage(format, "br", "\n");
final Component component = this.carbonChat.messageProcessor().processMessage(format, "br", "\n");
for (final Player player : Bukkit.getOnlinePlayers()) {
final ChatUser audience = this.carbonChat.userService().wrap(player.getUniqueId());
if (player.hasPermission("carbonchat.clearchat.exempt")) {
final String message = this.carbonChat.language().getString("clear-exempt");
audience.sendMessage(this.carbonChat.adventureManager().processMessage(message, "player", sender.getName()));
final String message = this.carbonChat.translations().clearExempt();
audience.sendMessage(this.carbonChat.messageProcessor().processMessage(message, "player", sender.getName()));
} else {
for (int i = 0; i < this.carbonChat.moderationConfig().getInt("clear-chat.message-count", 100); i++) {
audience.sendMessage(component);
@@ -50,8 +50,8 @@ public class ClearChatCommand {
}
if (player.hasPermission("carbonchat.clearchat.notify")) {
final String message = this.carbonChat.language().getString("clear-notify");
audience.sendMessage(this.carbonChat.adventureManager().processMessage(message, "player", sender.getName()));
final String message = this.carbonChat.translations().clearNotify();
audience.sendMessage(this.carbonChat.messageProcessor().processMessage(message, "player", sender.getName()));
}
}
}
@@ -6,7 +6,7 @@ import net.draycia.carbon.util.CommandUtils;
import dev.jorel.commandapi.CommandAPICommand;
import dev.jorel.commandapi.CommandPermission;
import dev.jorel.commandapi.arguments.Argument;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.CarbonChatBukkit;
import net.draycia.carbon.api.users.ChatUser;
import net.kyori.adventure.text.Component;
import net.milkbowl.vault.permission.Permission;
@@ -20,9 +20,9 @@ import java.util.LinkedHashMap;
public class IgnoreCommand {
@NonNull
private final CarbonChat carbonChat;
private final CarbonChatBukkit carbonChat;
public IgnoreCommand(@NonNull final CarbonChat carbonChat, @NonNull final CommandSettings commandSettings) {
public IgnoreCommand(@NonNull final CarbonChatBukkit carbonChat, @NonNull final CommandSettings commandSettings) {
this.carbonChat = carbonChat;
if (!commandSettings.enabled()) {
@@ -50,8 +50,8 @@ public class IgnoreCommand {
if (user.ignoringUser(targetUser)) {
user.ignoringUser(targetUser, false);
user.sendMessage(this.carbonChat.adventureManager().processMessageWithPapi(player,
this.carbonChat.language().getString("not-ignoring-user"),
user.sendMessage(this.carbonChat.messageProcessor().processMessage(
this.carbonChat.translations().notIgnoringUser(),
"br", "\n", "player", offlinePlayer.getName()));
} else {
Bukkit.getScheduler().runTaskAsynchronously(this.carbonChat, () -> {
@@ -59,13 +59,13 @@ public class IgnoreCommand {
final String format;
if (permission.playerHas(null, offlinePlayer, "carbonchat.ignore.exempt")) {
format = this.carbonChat.language().getString("ignore-exempt");
format = this.carbonChat.translations().ignoreExempt();
} else {
user.ignoringUser(targetUser, true);
format = this.carbonChat.language().getString("ignoring-user");
format = this.carbonChat.translations().ignoringUser();
}
final Component message = this.carbonChat.adventureManager().processMessageWithPapi(player, format,
final Component message = this.carbonChat.messageProcessor().processMessage(format,
"br", "\n", "sender", player.getDisplayName(), "player", offlinePlayer.getName());
user.sendMessage(message);
@@ -5,7 +5,7 @@ import dev.jorel.commandapi.CommandPermission;
import dev.jorel.commandapi.arguments.Argument;
import dev.jorel.commandapi.arguments.GreedyStringArgument;
import me.clip.placeholderapi.PlaceholderAPI;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.CarbonChatBukkit;
import net.draycia.carbon.api.users.ChatUser;
import net.draycia.carbon.api.commands.CommandSettings;
import net.draycia.carbon.util.CommandUtils;
@@ -19,9 +19,9 @@ import java.util.LinkedHashMap;
public class MeCommand {
@NonNull
private final CarbonChat carbonChat;
private final CarbonChatBukkit carbonChat;
public MeCommand(@NonNull final CarbonChat carbonChat, @NonNull final CommandSettings commandSettings) {
public MeCommand(@NonNull final CarbonChatBukkit carbonChat, @NonNull final CommandSettings commandSettings) {
this.carbonChat = carbonChat;
if (!commandSettings.enabled()) {
@@ -43,13 +43,13 @@ public class MeCommand {
private void execute(@NonNull final Player player, @NonNull final Object @NonNull [] args) {
final String message = ((String) args[0]).replace("</pre>", "");
String format = PlaceholderAPI.setPlaceholders(player, this.carbonChat.language().getString("me"));
String format = PlaceholderAPI.setPlaceholders(player, this.carbonChat.translations().roleplayFormat());
if (!player.hasPermission("carbonchat.me.formatting")) {
format = format.replace("<message>", "<pre><message></pre>");
}
final Component component = this.carbonChat.adventureManager().processMessage(format, "br", "\n",
final Component component = this.carbonChat.messageProcessor().processMessage(format, "br", "\n",
"displayname", player.getDisplayName(), "message", message);
final ChatUser user = this.carbonChat.userService().wrap(player.getUniqueId());
@@ -62,7 +62,7 @@ public class MeCommand {
continue;
}
this.carbonChat.adventureManager().audiences().player(onlinePlayer).sendMessage(component);
this.carbonChat.messageProcessor().audiences().player(onlinePlayer.getUniqueId()).sendMessage(component);
}
}
}
@@ -7,7 +7,7 @@ import dev.jorel.commandapi.CommandAPICommand;
import dev.jorel.commandapi.CommandPermission;
import dev.jorel.commandapi.arguments.Argument;
import dev.jorel.commandapi.arguments.GreedyStringArgument;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.CarbonChatBukkit;
import net.draycia.carbon.api.users.ChatUser;
import org.bukkit.entity.Player;
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -17,9 +17,9 @@ import java.util.LinkedHashMap;
public class MessageCommand {
@NonNull
private final CarbonChat carbonChat;
private final CarbonChatBukkit carbonChat;
public MessageCommand(@NonNull final CarbonChat carbonChat, @NonNull final CommandSettings commandSettings) {
public MessageCommand(@NonNull final CarbonChatBukkit carbonChat, @NonNull final CommandSettings commandSettings) {
this.carbonChat = carbonChat;
if (!commandSettings.enabled()) {
@@ -7,13 +7,14 @@ import net.draycia.carbon.util.CommandUtils;
import dev.jorel.commandapi.CommandAPICommand;
import dev.jorel.commandapi.CommandPermission;
import dev.jorel.commandapi.arguments.Argument;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.CarbonChatBukkit;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.LinkedHashMap;
@@ -21,9 +22,9 @@ import java.util.LinkedHashMap;
public class MuteCommand {
@NonNull
private final CarbonChat carbonChat;
private final CarbonChatBukkit carbonChat;
public MuteCommand(@NonNull final CarbonChat carbonChat, @NonNull final CommandSettings commandSettings) {
public MuteCommand(@NonNull final CarbonChatBukkit carbonChat, @NonNull final CommandSettings commandSettings) {
this.carbonChat = carbonChat;
if (!commandSettings.enabled()) {
@@ -45,34 +46,41 @@ public class MuteCommand {
private void execute(@NonNull final CommandSender sender, @NonNull final Object @NonNull [] args) {
final ChatUser user = (ChatUser) args[0];
final Audience audience = this.carbonChat.adventureManager().audiences().audience(sender);
final Audience cmdSender;
if (sender instanceof Player) {
cmdSender = this.carbonChat.userService().wrap(((Player) sender).getUniqueId());
} else {
cmdSender = this.carbonChat.messageProcessor().audiences().console();
}
final OfflinePlayer player = Bukkit.getOfflinePlayer(user.uuid());
if (user.shadowMuted()) {
user.muted(false);
final String format = this.carbonChat.language().getString("no-longer-muted");
final String format = this.carbonChat.translations().noLongerMuted();
final Component message = this.carbonChat.adventureManager().processMessage(format, "br", "\n",
final Component message = this.carbonChat.messageProcessor().processMessage(format, "br", "\n",
"player", player.getName());
audience.sendMessage(message);
cmdSender.sendMessage(message);
} else {
Bukkit.getScheduler().runTaskAsynchronously(this.carbonChat, () -> {
final Permission permission = this.carbonChat.permission();
final String format;
if (permission.playerHas(null, player, "carbonchat.mute.exempt")) {
format = this.carbonChat.language().getString("mute-exempt");
format = this.carbonChat.translations().muteExempt();
} else {
user.muted(true);
format = this.carbonChat.language().getString("is-now-muted");
format = this.carbonChat.translations().nowMuted();
}
final Component message = this.carbonChat.adventureManager().processMessage(format, "br", "\n",
final Component message = this.carbonChat.messageProcessor().processMessage(format, "br", "\n",
"player", player.getName());
audience.sendMessage(message);
cmdSender.sendMessage(message);
});
}
}
@@ -7,7 +7,7 @@ import dev.jorel.commandapi.CommandAPICommand;
import dev.jorel.commandapi.CommandPermission;
import dev.jorel.commandapi.arguments.Argument;
import dev.jorel.commandapi.arguments.StringArgument;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.CarbonChatBukkit;
import net.draycia.carbon.api.users.ChatUser;
import net.kyori.adventure.audience.Audience;
import org.bukkit.Bukkit;
@@ -20,9 +20,9 @@ import java.util.LinkedHashMap;
public class NicknameCommand {
@NonNull
private final CarbonChat carbonChat;
private final CarbonChatBukkit carbonChat;
public NicknameCommand(@NonNull final CarbonChat carbonChat, @NonNull final CommandSettings commandSettings) {
public NicknameCommand(@NonNull final CarbonChatBukkit carbonChat, @NonNull final CommandSettings commandSettings) {
this.carbonChat = carbonChat;
if (!commandSettings.enabled()) {
@@ -66,18 +66,25 @@ public class NicknameCommand {
final String message;
if (nickname == null) {
message = this.carbonChat.language().getString("nickname-reset");
message = this.carbonChat.translations().nicknameReset();
} else {
message = this.carbonChat.language().getString("nickname-set");
message = this.carbonChat.translations().nicknameSet();
}
sender.sendMessage(this.carbonChat.adventureManager().processMessage(
sender.sendMessage(this.carbonChat.messageProcessor().processMessage(
message, "nickname", nickname == null ? "" : nickname,
"user", Bukkit.getOfflinePlayer(sender.uuid()).getName()));
}
private void executeOther(@NonNull final CommandSender sender, @NonNull final Object @NonNull [] args) {
final Audience user = this.carbonChat.adventureManager().audiences().audience(sender);
final Audience cmdSender;
if (sender instanceof Player) {
cmdSender = this.carbonChat.userService().wrap(((Player) sender).getUniqueId());
} else {
cmdSender = this.carbonChat.messageProcessor().audiences().console();
}
final ChatUser target = (ChatUser) args[0];
String nickname = (String) args[1];
@@ -91,12 +98,12 @@ public class NicknameCommand {
final String message;
if (nickname == null) {
message = this.carbonChat.language().getString("other-nickname-reset");
message = this.carbonChat.translations().otherNicknameReset();
} else {
message = this.carbonChat.language().getString("other-nickname-set");
message = this.carbonChat.translations().otherNicknameSet();
}
user.sendMessage(this.carbonChat.adventureManager().processMessage(
cmdSender.sendMessage(this.carbonChat.messageProcessor().processMessage(
message, "nickname", nickname == null ? "" : nickname,
"user", Bukkit.getOfflinePlayer(target.uuid()).getName()));
}
@@ -4,7 +4,7 @@ import dev.jorel.commandapi.CommandAPICommand;
import dev.jorel.commandapi.CommandPermission;
import dev.jorel.commandapi.arguments.Argument;
import dev.jorel.commandapi.arguments.GreedyStringArgument;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.CarbonChatBukkit;
import net.draycia.carbon.api.users.ChatUser;
import net.draycia.carbon.api.commands.CommandSettings;
import net.draycia.carbon.util.CommandUtils;
@@ -17,9 +17,9 @@ import java.util.LinkedHashMap;
public class ReplyCommand {
@NonNull
private final CarbonChat carbonChat;
private final CarbonChatBukkit carbonChat;
public ReplyCommand(@NonNull final CarbonChat carbonChat, @NonNull final CommandSettings commandSettings) {
public ReplyCommand(@NonNull final CarbonChatBukkit carbonChat, @NonNull final CommandSettings commandSettings) {
this.carbonChat = carbonChat;
if (!commandSettings.enabled()) {
@@ -45,8 +45,8 @@ public class ReplyCommand {
final ChatUser user = this.carbonChat.userService().wrap(player.getUniqueId());
if (input.isEmpty()) {
final String message = this.carbonChat.language().getString("reply-message-blank");
final Component component = this.carbonChat.adventureManager().processMessage(message, "br", "\n");
final String message = this.carbonChat.translations().replyMessageBlank();
final Component component = this.carbonChat.messageProcessor().processMessage(message, "br", "\n");
user.sendMessage(component);
@@ -54,8 +54,8 @@ public class ReplyCommand {
}
if (user.replyTarget() == null) {
final String message = this.carbonChat.language().getString("no-reply-target");
final Component component = this.carbonChat.adventureManager().processMessage(message, "br", "\n");
final String message = this.carbonChat.translations().noReplyTarget();
final Component component = this.carbonChat.messageProcessor().processMessage(message, "br", "\n");
user.sendMessage(component);
@@ -4,7 +4,7 @@ import dev.jorel.commandapi.CommandAPICommand;
import dev.jorel.commandapi.CommandPermission;
import dev.jorel.commandapi.arguments.Argument;
import dev.jorel.commandapi.arguments.LiteralArgument;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.CarbonChatBukkit;
import net.draycia.carbon.api.channels.ChatChannel;
import net.draycia.carbon.api.users.ChatUser;
import net.draycia.carbon.api.commands.CommandSettings;
@@ -19,9 +19,9 @@ import java.util.LinkedHashMap;
public class SetColorCommand {
@NonNull
private final CarbonChat carbonChat;
private final CarbonChatBukkit carbonChat;
public SetColorCommand(@NonNull final CarbonChat carbonChat, @NonNull final CommandSettings commandSettings) {
public SetColorCommand(@NonNull final CarbonChatBukkit carbonChat, @NonNull final CommandSettings commandSettings) {
this.carbonChat = carbonChat;
if (!commandSettings.enabled()) {
@@ -30,7 +30,7 @@ public class SetColorCommand {
CommandUtils.handleDuplicateCommands(commandSettings);
for (final ChatChannel channel : this.carbonChat.channelManager().registry()) {
for (final ChatChannel channel : this.carbonChat.channelRegistry()) {
final LinkedHashMap<String, Argument> arguments = new LinkedHashMap<>();
arguments.put("channel", new LiteralArgument(channel.key()));
arguments.put("color", CarbonUtils.textColorArgument());
@@ -44,8 +44,8 @@ public class SetColorCommand {
final ChatUser user = this.carbonChat.userService().wrap(player.getUniqueId());
if (!player.hasPermission("carbonchat.setcolor." + channel.key())) {
user.sendMessage(carbonChat.adventureManager().processMessageWithPapi(player,
this.carbonChat.language().getString("cannot-set-color"),
user.sendMessage(carbonChat.messageProcessor().processMessage(
this.carbonChat.translations().cannotSetColor(),
"br", "\n", "input", color.asHexString(),
"channel", channel.name()));
@@ -56,8 +56,8 @@ public class SetColorCommand {
settings.color(color);
user.sendMessage(carbonChat.adventureManager().processMessageWithPapi(player,
this.carbonChat.language().getString("channel-color-set"),
user.sendMessage(carbonChat.messageProcessor().processMessage(
this.carbonChat.translations().channelColorSet(),
"br", "\n", "color", "<color:" + color.asHexString() + ">", "channel",
channel.name(), "hex", color.asHexString()));
})
@@ -7,13 +7,14 @@ import net.draycia.carbon.util.CommandUtils;
import dev.jorel.commandapi.CommandAPICommand;
import dev.jorel.commandapi.CommandPermission;
import dev.jorel.commandapi.arguments.Argument;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.CarbonChatBukkit;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.LinkedHashMap;
@@ -21,9 +22,9 @@ import java.util.LinkedHashMap;
public class ShadowMuteCommand {
@NonNull
private final CarbonChat carbonChat;
private final CarbonChatBukkit carbonChat;
public ShadowMuteCommand(@NonNull final CarbonChat carbonChat, @NonNull final CommandSettings commandSettings) {
public ShadowMuteCommand(@NonNull final CarbonChatBukkit carbonChat, @NonNull final CommandSettings commandSettings) {
this.carbonChat = carbonChat;
if (!commandSettings.enabled()) {
@@ -44,35 +45,42 @@ public class ShadowMuteCommand {
}
private void execute(@NonNull final CommandSender sender, @NonNull final Object @NonNull [] args) {
final Audience cmdSender;
if (sender instanceof Player) {
cmdSender = this.carbonChat.userService().wrap(((Player) sender).getUniqueId());
} else {
cmdSender = this.carbonChat.messageProcessor().audiences().console();
}
final ChatUser user = (ChatUser) args[0];
final Audience audience = this.carbonChat.adventureManager().audiences().audience(sender);
final OfflinePlayer player = Bukkit.getOfflinePlayer(user.uuid());
if (user.shadowMuted()) {
user.shadowMuted(false);
final String format = this.carbonChat.language().getString("no-longer-shadow-muted");
final String format = this.carbonChat.translations().noLongerShadowMuted();
final Component message = this.carbonChat.adventureManager().processMessage(format, "br", "\n",
final Component message = this.carbonChat.messageProcessor().processMessage(format, "br", "\n",
"player", player.getName());
audience.sendMessage(message);
cmdSender.sendMessage(message);
} else {
Bukkit.getScheduler().runTaskAsynchronously(this.carbonChat, () -> {
final Permission permission = this.carbonChat.permission();
final String format;
if (permission.playerHas(null, player, "carbonchat.shadowmute.exempt")) {
format = this.carbonChat.language().getString("shadow-mute-exempt");
format = this.carbonChat.translations().shadowMuteExempt();
} else {
user.shadowMuted(true);
format = this.carbonChat.language().getString("is-now-shadow-muted");
format = this.carbonChat.translations().nowShadowMuted();
}
final Component message = this.carbonChat.adventureManager().processMessage(format, "br", "\n",
final Component message = this.carbonChat.messageProcessor().processMessage(format, "br", "\n",
"player", player.getName());
audience.sendMessage(message);
cmdSender.sendMessage(message);
});
}
}
@@ -11,7 +11,7 @@ import dev.jorel.commandapi.CommandPermission;
import dev.jorel.commandapi.arguments.Argument;
import dev.jorel.commandapi.arguments.BooleanArgument;
import dev.jorel.commandapi.arguments.LiteralArgument;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.CarbonChatBukkit;
import org.bukkit.entity.Player;
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -20,9 +20,9 @@ import java.util.LinkedHashMap;
public class SpyChannelCommand {
@NonNull
private final CarbonChat carbonChat;
private final CarbonChatBukkit carbonChat;
public SpyChannelCommand(@NonNull final CarbonChat carbonChat, @NonNull final CommandSettings commandSettings) {
public SpyChannelCommand(@NonNull final CarbonChatBukkit carbonChat, @NonNull final CommandSettings commandSettings) {
this.carbonChat = carbonChat;
if (!commandSettings.enabled()) {
@@ -73,13 +73,13 @@ public class SpyChannelCommand {
if (settings.spying()) {
settings.spying(false);
message = this.carbonChat.language().getString("spy-toggled-off");
message = this.carbonChat.translations().spyToggledOff();
} else {
settings.spying(true);
message = this.carbonChat.language().getString("spy-toggled-on");
message = this.carbonChat.translations().spyToggledOn();
}
user.sendMessage(this.carbonChat.adventureManager().processMessageWithPapi(player, message, "br", "\n",
user.sendMessage(this.carbonChat.messageProcessor().processMessage(message, "br", "\n",
"color", "<color:" + chatChannel.channelColor(user).toString() + ">", "channel", chatChannel.name()));
}
@@ -90,13 +90,13 @@ public class SpyChannelCommand {
if (user.spyingwhispers()) {
user.spyingWhispers(false);
message = this.carbonChat.language().getString("spy-whispers-off");
message = this.carbonChat.translations().spyWhispersOff();
} else {
user.spyingWhispers(true);
message = this.carbonChat.language().getString("spy-whispers-on");
message = this.carbonChat.translations().spyWhispersOn();
}
user.sendMessage(this.carbonChat.adventureManager().processMessageWithPapi(player, message, "br", "\n"));
user.sendMessage(this.carbonChat.messageProcessor().processMessage(message, "br", "\n"));
}
private void executeEverything(@NonNull final Player player, @NonNull final Object @NonNull [] args) {
@@ -109,22 +109,22 @@ public class SpyChannelCommand {
if (shouldSpy) {
user.spyingWhispers(true);
for (final ChatChannel channel : this.carbonChat.channelManager().registry()) {
for (final ChatChannel channel : this.carbonChat.channelRegistry()) {
user.channelSettings(channel).spying(true);
}
message = this.carbonChat.language().getString("spy-everything-off");
message = this.carbonChat.translations().spyEverythingOff();
} else {
user.spyingWhispers(false);
for (final ChatChannel channel : this.carbonChat.channelManager().registry()) {
for (final ChatChannel channel : this.carbonChat.channelRegistry()) {
user.channelSettings(channel).spying(false);
}
message = this.carbonChat.language().getString("spy-everything-on");
message = this.carbonChat.translations().spyEverythingOn();
}
user.sendMessage(this.carbonChat.adventureManager().processMessageWithPapi(player, message, "br", "\n"));
user.sendMessage(this.carbonChat.messageProcessor().processMessage(message, "br", "\n"));
}
}
@@ -6,13 +6,15 @@ import dev.jorel.commandapi.CommandAPICommand;
import dev.jorel.commandapi.CommandPermission;
import dev.jorel.commandapi.arguments.Argument;
import dev.jorel.commandapi.arguments.GreedyStringArgument;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.CarbonChatBukkit;
import net.draycia.carbon.api.channels.ChatChannel;
import net.draycia.carbon.api.users.ChatUser;
import net.draycia.carbon.api.commands.CommandSettings;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.LinkedHashMap;
@@ -20,9 +22,9 @@ import java.util.LinkedHashMap;
public class SudoChannelCommand {
@NonNull
private final CarbonChat carbonChat;
private final CarbonChatBukkit carbonChat;
public SudoChannelCommand(@NonNull final CarbonChat carbonChat, @NonNull final CommandSettings commandSettings) {
public SudoChannelCommand(@NonNull final CarbonChatBukkit carbonChat, @NonNull final CommandSettings commandSettings) {
this.carbonChat = carbonChat;
if (!commandSettings.enabled()) {
@@ -65,11 +67,19 @@ public class SudoChannelCommand {
final String message = channel.switchMessage();
final String otherMessage = channel.switchOtherMessage();
user.sendMessage(this.carbonChat.adventureManager().processMessage(message, "br", "\n",
user.sendMessage(this.carbonChat.messageProcessor().processMessage(message, "br", "\n",
"color", "<color:" + channel.channelColor(user).toString() + ">", "channel", channel.name()));
this.carbonChat.adventureManager().audiences().audience(sender).sendMessage(
this.carbonChat.adventureManager().processMessage(otherMessage, "br", "\n",
final Audience cmdSender;
if (sender instanceof Player) {
cmdSender = this.carbonChat.userService().wrap(((Player) sender).getUniqueId());
} else {
cmdSender = this.carbonChat.messageProcessor().audiences().console();
}
cmdSender.sendMessage(
this.carbonChat.messageProcessor().processMessage(otherMessage, "br", "\n",
"color", "<color:" + channel.channelColor(user).toString() + ">", "channel", channel.name(),
"player", Bukkit.getOfflinePlayer(user.uuid()).getName()));
}
@@ -78,7 +88,7 @@ public class SudoChannelCommand {
@NonNull final ChatChannel channel, @NonNull final String message) {
final Component component = channel.sendMessage(user, message, false);
this.carbonChat.adventureManager().audiences().console().sendMessage(component);
this.carbonChat.messageProcessor().audiences().console().sendMessage(component);
}
}
@@ -9,7 +9,8 @@ import net.draycia.carbon.util.CommandUtils;
import dev.jorel.commandapi.CommandAPICommand;
import dev.jorel.commandapi.CommandPermission;
import dev.jorel.commandapi.arguments.Argument;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.CarbonChatBukkit;
import net.kyori.adventure.audience.Audience;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -20,9 +21,9 @@ import java.util.LinkedHashMap;
public class ToggleCommand {
@NonNull
private final CarbonChat carbonChat;
private final CarbonChatBukkit carbonChat;
public ToggleCommand(@NonNull final CarbonChat carbonChat, @NonNull final CommandSettings commandSettings) {
public ToggleCommand(@NonNull final CarbonChatBukkit carbonChat, @NonNull final CommandSettings commandSettings) {
this.carbonChat = carbonChat;
if (!commandSettings.enabled()) {
@@ -71,7 +72,7 @@ public class ToggleCommand {
message = channel.toggleOnMessage();
}
user.sendMessage(this.carbonChat.adventureManager().processMessageWithPapi(player, message, "br", "\n",
user.sendMessage(this.carbonChat.messageProcessor().processMessage(message, "br", "\n",
"color", "<color:" + channel.channelColor(user).toString() + ">", "channel", channel.name()));
}
@@ -94,11 +95,19 @@ public class ToggleCommand {
otherMessage = channel.toggleOtherOnMessage();
}
user.sendMessage(this.carbonChat.adventureManager().processMessage(message, "br", "\n",
user.sendMessage(this.carbonChat.messageProcessor().processMessage(message, "br", "\n",
"color", "<color:" + channel.channelColor(user).toString() + ">", "channel", channel.name()));
this.carbonChat.adventureManager().audiences().audience(sender).sendMessage(
this.carbonChat.adventureManager().processMessage(otherMessage,
final Audience cmdSender;
if (sender instanceof Player) {
cmdSender = this.carbonChat.userService().wrap(((Player) sender).getUniqueId());
} else {
cmdSender = this.carbonChat.messageProcessor().audiences().console();
}
cmdSender.sendMessage(
this.carbonChat.messageProcessor().processMessage(otherMessage,
"br", "\n", "color", "<color:" + channel.channelColor(user).toString() + ">",
"channel", channel.name(), "player", Bukkit.getOfflinePlayer(user.uuid()).getName()));
}
@@ -1,6 +1,6 @@
package net.draycia.carbon.listeners.contexts;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.CarbonChatBukkit;
import net.draycia.carbon.api.events.misc.CarbonEvents;
import net.draycia.carbon.api.events.PreChatFormatEvent;
import net.draycia.carbon.api.Context;
@@ -11,12 +11,12 @@ import org.checkerframework.checker.nullness.qual.NonNull;
public class EconomyContext {
@NonNull
private final CarbonChat carbonChat;
private final CarbonChatBukkit carbonChat;
@NonNull
private final Economy economy;
public EconomyContext(@NonNull final CarbonChat carbonChat) {
public EconomyContext(@NonNull final CarbonChatBukkit carbonChat) {
this.carbonChat = carbonChat;
this.economy = this.carbonChat.getServer().getServicesManager().getRegistration(Economy.class).getProvider();
@@ -44,7 +44,7 @@ public class EconomyContext {
if (!this.economy.has(player, requiredBal)) {
event.cancelled(true);
event.user().sendMessage(this.carbonChat.adventureManager()
event.user().sendMessage(this.carbonChat.messageProcessor()
.processMessage(event.channel().cannotUseMessage()));
}
});
@@ -73,7 +73,7 @@ public class EconomyContext {
if (!this.economy.has(player, cost)) {
event.cancelled(true);
event.user().sendMessage(this.carbonChat.adventureManager()
event.user().sendMessage(this.carbonChat.messageProcessor()
.processMessage(event.channel().cannotUseMessage()));
return;
@@ -1,7 +1,7 @@
package net.draycia.carbon.listeners.contexts;
import net.draycia.carbon.api.channels.ChatChannel;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.CarbonChatBukkit;
import net.draycia.carbon.api.events.misc.CarbonEvents;
import net.draycia.carbon.api.events.PreChatFormatEvent;
import net.draycia.carbon.api.Context;
@@ -20,7 +20,7 @@ import java.util.regex.Pattern;
public class FilterContext {
@NonNull
private final CarbonChat carbonChat;
private final CarbonChatBukkit carbonChat;
@NonNull
private final Map<String, List<@NonNull Pattern>> patternReplacements = new HashMap<>();
@@ -28,7 +28,7 @@ public class FilterContext {
@NonNull
private final List<@NonNull Pattern> blockedWords = new ArrayList<>();
public FilterContext(@NonNull final CarbonChat carbonChat) {
public FilterContext(@NonNull final CarbonChatBukkit carbonChat) {
this.carbonChat = carbonChat;
this.reloadFilters();
@@ -4,7 +4,7 @@ import com.palmergames.bukkit.towny.TownyAPI;
import com.palmergames.bukkit.towny.event.TownRemoveResidentEvent;
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import com.palmergames.bukkit.towny.object.Resident;
import net.draycia.carbon.CarbonChat;
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.ChannelSwitchEvent;
@@ -25,9 +25,9 @@ public final class TownyContext implements Listener {
private static final String KEY = "towny-town";
@NonNull
private final CarbonChat carbonChat;
private final CarbonChatBukkit carbonChat;
public TownyContext(@NonNull final CarbonChat carbonChat) {
public TownyContext(@NonNull final CarbonChatBukkit carbonChat) {
this.carbonChat = carbonChat;
CarbonEvents.register(ReceiverContextEvent.class, event -> {
@@ -2,7 +2,7 @@ package net.draycia.carbon.listeners.contexts;
import com.gmail.nossr50.api.PartyAPI;
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent;
import net.draycia.carbon.CarbonChat;
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.ChannelSwitchEvent;
@@ -20,12 +20,12 @@ import org.checkerframework.checker.nullness.qual.NonNull;
public final class mcMMOContext implements Listener {
@NonNull
private final CarbonChat carbonChat;
private final CarbonChatBukkit carbonChat;
@NonNull
private static final String KEY = "mcmmo-party";
public mcMMOContext(@NonNull final CarbonChat carbonChat) {
public mcMMOContext(@NonNull final CarbonChatBukkit carbonChat) {
this.carbonChat = carbonChat;
CarbonEvents.register(ReceiverContextEvent.class, PostOrders.NORMAL, false, event -> {
@@ -2,7 +2,7 @@ package net.draycia.carbon.listeners.events;
import net.draycia.carbon.api.channels.ChatChannel;
import net.draycia.carbon.api.users.ChatUser;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.CarbonChatBukkit;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer;
@@ -20,9 +20,9 @@ import java.util.HashSet;
public class BukkitChatListener implements Listener {
@NonNull
private final CarbonChat carbonChat;
private final CarbonChatBukkit carbonChat;
public BukkitChatListener(@NonNull final CarbonChat carbonChat) {
public BukkitChatListener(@NonNull final CarbonChatBukkit carbonChat) {
this.carbonChat = carbonChat;
}
@@ -33,18 +33,18 @@ public class BukkitChatListener implements Listener {
ChatChannel channel = user.selectedChannel();
if (channel == null) {
if (this.carbonChat.channelManager().defaultChannel() == null) {
if (this.carbonChat.channelRegistry().defaultChannel() == null) {
return;
}
channel = this.carbonChat.channelManager().defaultChannel();
channel = this.carbonChat.channelRegistry().defaultChannel();
}
if (channel.shouldCancelChatEvent()) {
event.setCancelled(true);
}
for (final ChatChannel entry : this.carbonChat.channelManager().registry()) {
for (final ChatChannel entry : this.carbonChat.channelRegistry()) {
if (entry.messagePrefix() == null || entry.messagePrefix().isEmpty()) {
continue;
}
@@ -89,7 +89,7 @@ public class BukkitChatListener implements Listener {
Bukkit.getScheduler().runTaskAsynchronously(this.carbonChat, () -> {
final Component component = selectedChannel.sendMessage(user, recipients, event.getMessage(), false);
this.carbonChat.adventureManager().audiences().console().sendMessage(component);
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. :(");
@@ -1,6 +1,6 @@
package net.draycia.carbon.listeners.events;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.CarbonChatBukkit;
import net.draycia.carbon.api.events.misc.CarbonEvents;
import net.draycia.carbon.api.events.PreChatFormatEvent;
import net.kyori.event.PostOrders;
@@ -8,7 +8,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
public class CapsHandler {
public CapsHandler(@NonNull final CarbonChat carbonChat) {
public CapsHandler(@NonNull final CarbonChatBukkit carbonChat) {
CarbonEvents.register(PreChatFormatEvent.class, PostOrders.FIRST, false, event -> {
if (!carbonChat.moderationConfig().getBoolean("caps-protection.enabled")) {
return;
@@ -1,6 +1,6 @@
package net.draycia.carbon.listeners.events;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.CarbonChatBukkit;
import net.draycia.carbon.api.events.misc.CarbonEvents;
import net.draycia.carbon.api.events.PreChatFormatEvent;
import net.kyori.event.PostOrders;
@@ -9,7 +9,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
public class CustomPlaceholderHandler {
public CustomPlaceholderHandler(@NonNull final CarbonChat carbonChat) {
public CustomPlaceholderHandler(@NonNull final CarbonChatBukkit carbonChat) {
CarbonEvents.register(PreChatFormatEvent.class, PostOrders.FIRST, false, event -> {
final ConfigurationSection placeholders = carbonChat.getConfig().getConfigurationSection("placeholders");
@@ -1,6 +1,6 @@
package net.draycia.carbon.listeners.events;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.CarbonChatBukkit;
import net.draycia.carbon.api.events.misc.CarbonEvents;
import net.draycia.carbon.api.events.ChatComponentEvent;
import net.kyori.adventure.key.Key;
@@ -11,7 +11,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
public class PingHandler {
public PingHandler(@NonNull final CarbonChat carbonChat) {
public PingHandler(@NonNull final CarbonChatBukkit carbonChat) {
CarbonEvents.register(ChatComponentEvent.class, PostOrders.LAST, false, event -> {
if (!carbonChat.getConfig().getBoolean("pings.enabled")) {
return;
@@ -2,7 +2,7 @@ package net.draycia.carbon.listeners.events;
import net.draycia.carbon.api.channels.ChatChannel;
import net.draycia.carbon.api.users.ChatUser;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.CarbonChatBukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
@@ -12,9 +12,9 @@ import org.checkerframework.checker.nullness.qual.NonNull;
public class PlayerJoinListener implements Listener {
@NonNull
private final CarbonChat carbonChat;
private final CarbonChatBukkit carbonChat;
public PlayerJoinListener(@NonNull final CarbonChat carbonChat) {
public PlayerJoinListener(@NonNull final CarbonChatBukkit carbonChat) {
this.carbonChat = carbonChat;
}
@@ -35,11 +35,11 @@ public class PlayerJoinListener implements Listener {
}
if (channel.equals("DEFAULT")) {
user.selectedChannel(this.carbonChat.channelManager().defaultChannel());
user.selectedChannel(this.carbonChat.channelRegistry().defaultChannel());
return;
}
final ChatChannel chatChannel = this.carbonChat.channelManager().registry().get(channel);
final ChatChannel chatChannel = this.carbonChat.channelRegistry().get(channel);
if (chatChannel != null) {
user.selectedChannel(chatChannel);
@@ -1,6 +1,6 @@
package net.draycia.carbon.listeners.events;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.CarbonChatBukkit;
import net.draycia.carbon.api.events.misc.CarbonEvents;
import net.draycia.carbon.api.events.ChatComponentEvent;
import net.draycia.carbon.api.events.ChatFormatEvent;
@@ -9,7 +9,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
public class ShadowMuteHandler {
public ShadowMuteHandler(@NonNull final CarbonChat carbonChat) {
public ShadowMuteHandler(@NonNull final CarbonChatBukkit carbonChat) {
CarbonEvents.register(ChatComponentEvent.class, PostOrders.FIRST, false, event -> {
if (event.sender().shadowMuted() && event.sender().equals(event.target())) {
event.cancelled(true);
@@ -1,6 +1,6 @@
package net.draycia.carbon.listeners.events;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.CarbonChatBukkit;
import net.draycia.carbon.api.events.misc.CarbonEvents;
import net.draycia.carbon.api.events.PreChatFormatEvent;
import net.kyori.adventure.text.minimessage.MiniMessage;
@@ -20,7 +20,7 @@ public class UserFormattingHandler {
this.suppressFormatting(event);
} else {
// Swap the &-style codes for minimessage-compatible strings
event.message(MiniMessage.get().serialize(CarbonChat.LEGACY.deserialize(event.message())));
event.message(MiniMessage.get().serialize(CarbonChatBukkit.LEGACY.deserialize(event.message())));
}
});
}
@@ -1,6 +1,6 @@
package net.draycia.carbon.listeners.events;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.CarbonChatBukkit;
import net.draycia.carbon.api.events.misc.CarbonEvents;
import net.draycia.carbon.api.events.PrivateMessageEvent;
import net.kyori.adventure.key.Key;
@@ -11,7 +11,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
public class WhisperPingHandler {
public WhisperPingHandler(@NonNull final CarbonChat carbonChat) {
public WhisperPingHandler(@NonNull final CarbonChatBukkit carbonChat) {
CarbonEvents.register(PrivateMessageEvent.class, PostOrders.LAST, false, event -> {
if (event.sender().uuid().equals(event.target().uuid())) {
@@ -1,74 +0,0 @@
package net.draycia.carbon.managers;
import de.themoep.minedown.adventure.MineDown;
import me.clip.placeholderapi.PlaceholderAPI;
import net.draycia.carbon.CarbonChat;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.entity.Player;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
public class AdventureManager {
@NonNull
private final CarbonChat carbonChat;
@NonNull
private final BukkitAudiences audiences;
public AdventureManager(@NonNull final CarbonChat carbonChat) {
this.carbonChat = carbonChat;
this.audiences = BukkitAudiences.create(carbonChat);
}
@NonNull
public Component processMessageWithPapi(@NonNull final Player player, @Nullable final String input,
@NonNull final String @NonNull ... placeholders) {
if (input == null || input.trim().isEmpty()) {
return TextComponent.empty();
}
return this.processMessage(PlaceholderAPI.setPlaceholders(player, input), placeholders);
}
@NonNull
public Component processMessage(@Nullable final String input, @NonNull final String @NonNull ... placeholders) {
if (input == null || input.trim().isEmpty()) {
return TextComponent.empty();
}
switch (this.carbonChat.language().getString("formatting.type", "minimessage").toLowerCase()) {
case "minedown":
return MineDown.parse(input, placeholders);
case "mojang":
case "mojangson":
case "json":
return this.processMojang(input, placeholders);
case "minimessage-markdown":
return MiniMessage.markdown().parse(input, placeholders);
case "minimessage":
default:
return MiniMessage.get().parse(input, placeholders);
}
}
@NonNull
private Component processMojang(@NonNull String input, @NonNull final String @NonNull ... placeholders) {
for (int i = 0; i < placeholders.length; i += 2) {
final String placeholder = placeholders[i];
final String replacement = placeholders[i + 1];
input = input.replace("<" + placeholder + ">", replacement);
}
return this.audiences().gsonSerializer().deserialize(input);
}
@NonNull
public BukkitAudiences audiences() {
return this.audiences;
}
}
@@ -1,7 +1,7 @@
package net.draycia.carbon.managers;
import net.draycia.carbon.channels.CarbonChatChannel;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.CarbonChatBukkit;
import net.draycia.carbon.api.channels.ChannelRegistry;
import net.draycia.carbon.api.channels.ChatChannel;
import net.draycia.carbon.api.events.misc.CarbonEvents;
@@ -17,7 +17,7 @@ import java.util.Collections;
public class ChannelManager {
@NonNull
private final CarbonChat carbonChat;
private final CarbonChatBukkit carbonChat;
@NonNull
private final ChannelRegistry registry;
@@ -26,7 +26,7 @@ public class ChannelManager {
@MonotonicNonNull
private String defaultChannelKey = null;
public ChannelManager(@NonNull final CarbonChat carbonChat) {
public ChannelManager(@NonNull final CarbonChatBukkit carbonChat) {
this.carbonChat = carbonChat;
this.registry = new ChannelRegistry();
@@ -15,17 +15,16 @@ import net.draycia.carbon.commands.SpyChannelCommand;
import net.draycia.carbon.commands.SudoChannelCommand;
import net.draycia.carbon.commands.ToggleCommand;
import net.draycia.carbon.api.commands.CommandSettings;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.CarbonChatBukkit;
import net.draycia.carbon.commands.ShadowMuteCommand;
import org.bukkit.configuration.ConfigurationSection;
import org.checkerframework.checker.nullness.qual.NonNull;
public class CommandManager {
@NonNull
private final CarbonChat carbonChat;
private final CarbonChatBukkit carbonChat;
public CommandManager(@NonNull final CarbonChat carbonChat) {
public CommandManager(@NonNull final CarbonChatBukkit carbonChat) {
this.carbonChat = carbonChat;
this.reloadCommands();
@@ -51,10 +50,7 @@ public class CommandManager {
@NonNull
private CommandSettings commandSettings(@NonNull final String command) {
final ConfigurationSection section = this.carbonChat.commandsConfig().getConfigurationSection(command);
return new CommandSettings(section.getBoolean("enabled"), section.getString("name"),
section.getStringList("aliases"));
return this.carbonChat.commandSettingsRegistry().get(command);
}
}
@@ -4,7 +4,7 @@ import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import io.github.leonardosnt.bungeechannelapi.BungeeChannelApi;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.CarbonChatBukkit;
import net.draycia.carbon.api.messaging.MessageService;
import net.draycia.carbon.api.users.ChatUser;
import org.bukkit.entity.Player;
@@ -19,7 +19,7 @@ import java.util.function.Consumer;
public class BungeeMessageService implements MessageService {
@NonNull
private final CarbonChat carbonChat;
private final CarbonChatBukkit carbonChat;
@NonNull
private final BungeeChannelApi api;
@@ -33,7 +33,7 @@ public class BungeeMessageService implements MessageService {
@NonNull
private final UUID serverUUID = UUID.randomUUID();
public BungeeMessageService(@NonNull final CarbonChat carbonChat) {
public BungeeMessageService(@NonNull final CarbonChatBukkit carbonChat) {
this.carbonChat = carbonChat;
this.carbonChat.getServer().getMessenger().registerOutgoingPluginChannel(carbonChat, "BungeeCord");
@@ -5,7 +5,7 @@ import net.draycia.carbon.api.users.ChatUser;
import net.draycia.carbon.api.users.UserChannelSettings;
import net.draycia.carbon.util.FunctionalityConstants;
import io.github.leonardosnt.bungeechannelapi.BungeeChannelApi;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.CarbonChatBukkit;
import net.draycia.carbon.api.events.misc.CarbonEvents;
import net.draycia.carbon.api.events.ChannelSwitchEvent;
import net.draycia.carbon.api.events.PrivateMessageEvent;
@@ -31,7 +31,7 @@ import java.util.UUID;
public class CarbonChatUser implements ChatUser, ForwardingAudience {
@NonNull
private final transient CarbonChat carbonChat;
private final transient CarbonChatBukkit carbonChat;
@NonNull
private final Map<@NonNull String, @NonNull SimpleUserChannelSettings> channelSettings = new HashMap<>();
@NonNull
@@ -51,7 +51,7 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
private transient UUID replyTarget = null;
public CarbonChatUser() {
this.carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
this.carbonChat = (CarbonChatBukkit) Bukkit.getPluginManager().getPlugin("CarbonChat");
}
public CarbonChatUser(@NonNull final UUID uuid) {
@@ -62,7 +62,7 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
@Override
@NonNull
public Iterable<@NonNull ? extends Audience> audiences() {
return Collections.singleton(this.carbonChat.adventureManager().audiences().player(this.uuid));
return Collections.singleton(this.carbonChat.messageProcessor().audiences().player(this.uuid));
}
@Override
@@ -95,8 +95,8 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
if (player.isOnline()) {
if (newNickname != null) {
final Component component = this.carbonChat.adventureManager().processMessage(this.nickname);
newNickname = CarbonChat.LEGACY.serialize(component);
final Component component = this.carbonChat.messageProcessor().processMessage(this.nickname);
newNickname = CarbonChatBukkit.LEGACY.serialize(component);
}
final Player onlinePlayer = player.getPlayer();
@@ -127,7 +127,7 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
return null;
}
return this.carbonChat.channelManager().channelOrDefault(this.selectedChannel);
return this.carbonChat.channelRegistry().channelOrDefault(this.selectedChannel);
}
@Override
@@ -139,7 +139,7 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
CarbonEvents.post(event);
if (event.cancelled()) {
this.sendMessage(this.carbonChat.adventureManager().processMessage(event.failureMessage(),
this.sendMessage(this.carbonChat.messageProcessor().processMessage(event.failureMessage(),
"channel", chatChannel.name()));
return;
@@ -156,7 +156,7 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
final OfflinePlayer player = Bukkit.getOfflinePlayer(this.uuid());
if (player.isOnline()) {
this.sendMessage(this.carbonChat.adventureManager().processMessageWithPapi(player.getPlayer(), chatChannel.switchMessage(),
this.sendMessage(this.carbonChat.messageProcessor().processMessage(chatChannel.switchMessage(),
"br", "\n",
"color", "<" + chatChannel.channelColor(this).toString() + ">",
"channel", chatChannel.name()));
@@ -165,7 +165,7 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
@Override
public void clearSelectedChannel() {
this.selectedChannel(this.carbonChat.channelManager().defaultChannel());
this.selectedChannel(this.carbonChat.channelRegistry().defaultChannel());
}
@Override
@@ -280,8 +280,8 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
return;
}
final String toPlayerFormat = this.carbonChat.language().getString("message-to-other");
final String fromPlayerFormat = this.carbonChat.language().getString("message-from-other");
final String toPlayerFormat = this.carbonChat.translations().messageToOther();
final String fromPlayerFormat = this.carbonChat.translations().messageFromOther();
final OfflinePlayer offlineSender = Bukkit.getOfflinePlayer(sender.uuid());
String senderName = offlineSender.getName();
@@ -299,12 +299,12 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
targetName = offlineTarget.getPlayer().getDisplayName();
}
final Component toPlayerComponent = this.carbonChat.adventureManager().processMessage(toPlayerFormat, "br", "\n",
final Component toPlayerComponent = this.carbonChat.messageProcessor().processMessage(toPlayerFormat, "br", "\n",
"message", message,
"targetname", targetOfflineName, "sendername", senderOfflineName,
"target", targetName, "sender", senderName);
final Component fromPlayerComponent = this.carbonChat.adventureManager().processMessage(fromPlayerFormat, "br", "\n",
final Component fromPlayerComponent = this.carbonChat.messageProcessor().processMessage(fromPlayerFormat, "br", "\n",
"message", message,
"targetname", targetOfflineName, "sendername", senderOfflineName,
"target", targetName, "sender", senderName);
@@ -344,9 +344,9 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
final String senderNameFinal = senderName;
if (!FunctionalityConstants.HAS_PROXY) {
final String playerOfflineFormat = this.carbonChat.language().getString("other-player-offline");
final String playerOfflineFormat = this.carbonChat.translations().otherPlayerOffline();
final Component playerOfflineComponent = this.carbonChat.adventureManager().processMessage(playerOfflineFormat,
final Component playerOfflineComponent = this.carbonChat.messageProcessor().processMessage(playerOfflineFormat,
"br", "\n",
"message", message,
"targetname", targetOfflineName, "sendername", senderOfflineName,
@@ -361,9 +361,9 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
final OfflinePlayer player = Bukkit.getOfflinePlayer(this.uuid());
if (!list.contains(player.getName())) {
final String playerOfflineFormat = this.carbonChat.language().getString("other-player-offline");
final String playerOfflineFormat = this.carbonChat.translations().otherPlayerOffline();
final Component playerOfflineComponent = this.carbonChat.adventureManager().processMessage(playerOfflineFormat,
final Component playerOfflineComponent = this.carbonChat.messageProcessor().processMessage(playerOfflineFormat,
"br", "\n",
"message", message,
"targetname", targetOfflineName, "sendername", senderOfflineName,
@@ -379,7 +379,7 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
this.carbonChat.messageManager().sendMessage("whisper-component", sender.uuid(), byteArray -> {
byteArray.writeLong(this.uuid().getMostSignificantBits());
byteArray.writeLong(this.uuid().getLeastSignificantBits());
byteArray.writeUTF(this.carbonChat.adventureManager().audiences().gsonSerializer().serialize(fromPlayerComponent));
byteArray.writeUTF(this.carbonChat.messageProcessor().audiences().gsonSerializer().serialize(fromPlayerComponent));
});
});
}
@@ -395,7 +395,7 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
continue;
}
user.sendMessage(this.carbonChat.adventureManager().processMessage(this.carbonChat.language().getString("spy-whispers"),
user.sendMessage(this.carbonChat.messageProcessor().processMessage(this.carbonChat.translations().spyWhispers(),
"br", "\n", "message", message,
"targetname", targetOfflineName, "sendername", senderOfflineName,
"target", targetName, "sender", senderName));
@@ -9,7 +9,7 @@ import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.CarbonChatBukkit;
import net.draycia.carbon.api.users.ChatUser;
import net.draycia.carbon.api.users.UserService;
import org.bukkit.Bukkit;
@@ -27,7 +27,7 @@ import java.util.concurrent.ExecutionException;
public class JSONUserService implements UserService {
@NonNull
private final CarbonChat carbonChat;
private final CarbonChatBukkit carbonChat;
@NonNull
private final Gson gson = new GsonBuilder().setPrettyPrinting().create();
@NonNull
@@ -37,7 +37,7 @@ public class JSONUserService implements UserService {
.removalListener(this::saveUser)
.build(CacheLoader.from(this::loadUser));
public JSONUserService(@NonNull final CarbonChat carbonChat) {
public JSONUserService(@NonNull final CarbonChatBukkit carbonChat) {
this.carbonChat = carbonChat;
Bukkit.getScheduler().scheduleSyncRepeatingTask(carbonChat, this.userCache::cleanUp, 0L, 20 * 60 * 10);
@@ -12,7 +12,7 @@ import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.cache.RemovalNotification;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.CarbonChatBukkit;
import net.draycia.carbon.api.users.ChatUser;
import net.draycia.carbon.api.users.UserService;
import net.kyori.adventure.text.format.TextColor;
@@ -30,7 +30,7 @@ import java.util.concurrent.ExecutionException;
public class MySQLUserService implements UserService {
@NonNull
private final CarbonChat carbonChat;
private final CarbonChatBukkit carbonChat;
@NonNull
private final Database database;
@NonNull
@@ -38,7 +38,7 @@ public class MySQLUserService implements UserService {
.removalListener(this::saveUser)
.build(CacheLoader.from(this::loadUser));
public MySQLUserService(@NonNull final CarbonChat carbonChat) {
public MySQLUserService(@NonNull final CarbonChatBukkit carbonChat) {
this.carbonChat = carbonChat;
final ConfigurationSection section = this.carbonChat.getConfig().getConfigurationSection("storage");
@@ -134,7 +134,7 @@ public class MySQLUserService implements UserService {
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.channelManager().channelOrDefault(users.getString("channel"));
final ChatChannel channel = this.carbonChat.channelRegistry().channelOrDefault(users.getString("channel"));
if (channel != null) {
user.selectedChannel(channel, true);
@@ -151,7 +151,7 @@ public class MySQLUserService implements UserService {
user.spyingWhispers(users.<Boolean>get("spyingwhispers"), true);
for (final DbRow channelSetting : channelSettings) {
final ChatChannel chatChannel = this.carbonChat.channelManager().registry().get(channelSetting.getString("channel"));
final ChatChannel chatChannel = this.carbonChat.channelRegistry().get(channelSetting.getString("channel"));
if (chatChannel != null) {
final UserChannelSettings settings = user.channelSettings(chatChannel);
@@ -1,7 +1,7 @@
package net.draycia.carbon.storage.impl;
import net.draycia.carbon.api.users.UserChannelSettings;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.CarbonChatBukkit;
import net.kyori.adventure.text.format.TextColor;
import org.bukkit.Bukkit;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
@@ -13,7 +13,7 @@ import java.util.UUID;
public class SimpleUserChannelSettings implements UserChannelSettings {
@NonNull
private final transient CarbonChat carbonChat;
private final transient CarbonChatBukkit carbonChat;
private boolean spying;
private boolean ignored;
@Nullable
@@ -24,14 +24,14 @@ public class SimpleUserChannelSettings implements UserChannelSettings {
private String channel;
private SimpleUserChannelSettings() {
this.carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
this.carbonChat = (CarbonChatBukkit) Bukkit.getPluginManager().getPlugin("CarbonChat");
}
public SimpleUserChannelSettings(@NonNull final UUID uuid, @NonNull final String channel) {
this.uuid = uuid;
this.channel = channel;
this.carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
this.carbonChat = (CarbonChatBukkit) Bukkit.getPluginManager().getPlugin("CarbonChat");
}
@NonNull
@@ -3,7 +3,7 @@ package net.draycia.carbon.util;
import net.draycia.carbon.api.channels.ChatChannel;
import net.draycia.carbon.api.users.ChatUser;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.CarbonChatBukkit;
import org.bukkit.entity.Player;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
@@ -11,9 +11,9 @@ import org.checkerframework.checker.nullness.qual.Nullable;
public class CarbonPlaceholders extends PlaceholderExpansion {
@NonNull
private final CarbonChat carbonChat;
private final CarbonChatBukkit carbonChat;
public CarbonPlaceholders(@NonNull final CarbonChat carbonChat) {
public CarbonPlaceholders(@NonNull final CarbonChatBukkit carbonChat) {
this.carbonChat = carbonChat;
}
@@ -48,7 +48,7 @@ public class CarbonPlaceholders extends PlaceholderExpansion {
if (key.startsWith("can_use_")) {
final String value = key.replace("can_use_", "");
final ChatChannel channel = this.carbonChat.channelManager().registry().get(value);
final ChatChannel channel = this.carbonChat.channelRegistry().get(value);
if (channel == null) {
return "false";
@@ -60,7 +60,7 @@ public class CarbonPlaceholders extends PlaceholderExpansion {
} else if (key.startsWith("can_see_")) {
final String value = key.replace("can_see_", "");
final ChatChannel channel = this.carbonChat.channelManager().registry().get(value);
final ChatChannel channel = this.carbonChat.channelRegistry().get(value);
if (channel == null) {
return "false";
@@ -72,7 +72,7 @@ public class CarbonPlaceholders extends PlaceholderExpansion {
} else if (key.startsWith("ignoring_channel_")) {
final String value = key.replace("ignoring_channel_", "");
final ChatChannel channel = this.carbonChat.channelManager().registry().get(value);
final ChatChannel channel = this.carbonChat.channelRegistry().get(value);
if (channel == null) {
return "false";
@@ -84,7 +84,7 @@ public class CarbonPlaceholders extends PlaceholderExpansion {
} else if (key.startsWith("selected_channel")) {
final ChatChannel channel = this.carbonChat.userService().wrap(player.getUniqueId()).selectedChannel();
return channel == null ? this.carbonChat.channelManager().defaultChannel().name() : channel.name();
return channel == null ? this.carbonChat.channelRegistry().defaultChannel().name() : channel.name();
}
return null;
@@ -23,7 +23,7 @@ package net.draycia.carbon.util;
import dev.jorel.commandapi.arguments.Argument;
import dev.jorel.commandapi.arguments.CustomArgument;
import me.clip.placeholderapi.PlaceholderAPI;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.CarbonChatBukkit;
import net.draycia.carbon.api.channels.ChatChannel;
import net.draycia.carbon.api.users.ChatUser;
import net.kyori.adventure.text.Component;
@@ -136,7 +136,7 @@ public final class CarbonUtils {
@NonNull
public static Argument onlineChatUserArgument() {
return new CustomArgument<>(input -> {
final CarbonChat carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
final CarbonChatBukkit carbonChat = (CarbonChatBukkit) Bukkit.getPluginManager().getPlugin("CarbonChat");
final Player player = Bukkit.getPlayer(input);
@@ -159,7 +159,7 @@ public final class CarbonUtils {
@NonNull
public static Argument chatUserArgument() {
return new CustomArgument<>(input -> {
final CarbonChat carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
final CarbonChatBukkit carbonChat = (CarbonChatBukkit) Bukkit.getPluginManager().getPlugin("CarbonChat");
return carbonChat.userService().wrap(Bukkit.getOfflinePlayer(input).getUniqueId());
// }).overrideSuggestions((sender, args) -> {
@@ -189,9 +189,9 @@ public final class CarbonUtils {
@NonNull
public static Argument channelArgument() {
return new CustomArgument<>(input -> {
final CarbonChat carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
final CarbonChatBukkit carbonChat = (CarbonChatBukkit) Bukkit.getPluginManager().getPlugin("CarbonChat");
final ChatChannel channel = carbonChat.channelManager().registry().get(input);
final ChatChannel channel = carbonChat.channelRegistry().get(input);
if (channel == null) {
throw new CustomArgument.CustomArgumentException("Invalid channel for input (" + input + ")");
@@ -1,48 +0,0 @@
# Options:
# 'MiniMessage': https://docs.adventure.kyori.net/minimessage.html#format
# 'MiniMessage-Markdown': https://docs.adventure.kyori.net/minimessage.html#markdown
# 'MineDown': https://github.com/Phoenix616/MineDown#syntax
# 'JSON': https://minecraft.gamepedia.com/Raw_JSON_text_format
# Note that the messages provided in the default config utilise MiniMessage, and need to be changed if you're using MineDown
# Please DO NOT use JSON formatting unless you really know what you're doing
formatting:
type: 'MiniMessage'
# The following messages are only compatible with MiniMessage/MineDown
reloaded: '<yellow>Chat config has been reloaded!'
message-to-other: '<green>[<gray>Me <gold>-> <gray><target><reset><green>] <message>'
message-from-other: '<green>[<gray><sender><reset> <gold>-> <gray>Me<green>] <message>'
other-player-offline: '<red>That player is offline!'
spy-whispers: '<yellow>Spy [<gray><sender><reset> <gold>-> <gray><target><reset><yellow>] <message>'
no-reply-target: '<red>You have no one to reply to!'
empty-channel: 'NONE' #<channel>, set to "NONE" to disable
other-nickname-set: '<green><user><reset>''s nickname was set to <nickname><green>!'
other-nickname-reset: '<green><user><reset>''s nickname was reset!'
available-channels-list: '<green>Available Channels:<reset> <list>.'
unavailable-channels-list: '<red>Unavailable Channels:<reset> <list>.'
channel-list-separator: ', '
user-must-be-online: '<red><player> must be online!'
reply-message-blank: '<red>Your reply message was blank!'
invalid-color: '<red>The input <input> is not a valid color!'
cannot-set-color: '<red>You do not have permission to set a color for this channel!'
# The following messages are compatible with PlaceholderAPI and MiniMessage/MineDown
me: '<italic><dark_purple>*<displayname> <reset><message>*</dark_purple></italic>'
ignoring-user: '<green>You are now ignoring <gold><player><reset><green>!'
not-ignoring-user: '<green>You are no longer ignoring <gold><player><reset><green>!'
ignore-exempt: '<red>User <player> <red>is exempt from being ignored!'
channel-color-set: '<green>You have set <color><channel> <green>color to <hex>!'
spy-toggled-on: '<gray>You are now spying on <color><channel> <gray>chat!'
spy-toggled-off: '<gray>You are no longer spying on <color><channel> <gray>chat!'
spy-whispers-on: '<gray>You are now spying on whispers!'
spy-whispers-off: '<gray>You are no longer spying on whispers!'
nickname-set: '<green>Your nickname was set to <nickname><reset><green>!'
nickname-reset: '<green>Your nickname was reset!'
is-now-shadow-muted: '<yellow>Player <player> is now shadow muted!'
no-longer-shadow-muted: '<yellow>Player <player> is no longer shadow muted!'
shadow-mute-exempt: '<red>Player <player> is exempt from being shadow muted!'
is-now-muted: '<yellow>Player <player> is now muted!'
no-longer-muted: '<yellow>Player <player> is no longer muted!'
mute-exempt: '<red>Player <player> is exempt from being muted!'
clear-notify: '<yellow>Chat has been cleared by <player>.'
clear-exempt: '<yellow>You were exempt from the clear due to your permissions!'
+13
View File
@@ -0,0 +1,13 @@
description 'CarbonChat-Common'
dependencies {
checkstyle("ca.stellardrift:stylecheck:0.1-SNAPSHOT")
compile project(':CarbonChat-API')
compile('io.lettuce:lettuce-core:6.0.0.M1') {
exclude group: 'io.netty'
}
compile 'org.spongepowered:configurate-yaml:4.0.0-SNAPSHOT'
}
@@ -0,0 +1,59 @@
package net.draycia.carbon.common.adventure;
import de.themoep.minedown.adventure.MineDown;
import net.draycia.carbon.api.adventure.MessageProcessor;
import net.kyori.adventure.platform.AudienceProvider;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
public class AdventureManager implements MessageProcessor {
@NonNull
private final AudienceProvider provider;
@NonNull
private final FormatType formatType;
public AdventureManager(@NonNull final AudienceProvider provider, @NonNull final FormatType formatType) {
this.provider = provider;
this.formatType = formatType;
}
@Override
public @NonNull Component processMessage(@Nullable final String input, @NonNull final String @NonNull ... placeholders) {
if (input == null || input.trim().isEmpty()) {
return TextComponent.empty();
}
switch (this.formatType) {
case MINEDOWN:
return MineDown.parse(input, placeholders);
case MOJANG:
return this.processMojang(input, placeholders);
case MINIMESSAGE_MARKDOWN:
return MiniMessage.markdown().parse(input, placeholders);
case MINIMESSAGE:
default:
return MiniMessage.get().parse(input, placeholders);
}
}
private @NonNull Component processMojang(@NonNull String input, @NonNull final String @NonNull ... placeholders) {
for (int i = 0; i < placeholders.length; i += 2) {
final String placeholder = placeholders[i];
final String replacement = placeholders[i + 1];
input = input.replace("<" + placeholder + ">", replacement);
}
return this.audiences().gsonSerializer().deserialize(input);
}
@Override
public @NonNull AudienceProvider audiences() {
return this.provider;
}
}
@@ -0,0 +1,8 @@
package net.draycia.carbon.common.adventure;
public enum FormatType {
MOJANG,
MINIMESSAGE_MARKDOWN,
MINIMESSAGE,
MINEDOWN
}
@@ -1,4 +1,4 @@
package net.draycia.carbon.messaging.impl;
package net.draycia.carbon.common.messaging;
import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteArrayDataOutput;
@@ -1,18 +1,13 @@
package net.draycia.carbon.messaging;
package net.draycia.carbon.common.messaging;
import net.draycia.carbon.api.CarbonChat;
import net.draycia.carbon.api.messaging.MessageService;
import net.draycia.carbon.messaging.impl.BungeeMessageService;
import com.google.common.io.ByteArrayDataOutput;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.api.channels.ChatChannel;
import net.draycia.carbon.messaging.impl.EmptyMessageService;
import net.draycia.carbon.messaging.impl.RedisMessageService;
import net.draycia.carbon.api.users.ChatUser;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.UUID;
@@ -29,33 +24,10 @@ public class MessageManager {
@NonNull
private final GsonComponentSerializer gsonSerializer;
public MessageManager(@NonNull final CarbonChat carbonChat) {
public MessageManager(final @NonNull CarbonChat carbonChat, @NonNull final MessageService messageService) {
this.carbonChat = carbonChat;
this.gsonSerializer = this.carbonChat.adventureManager().audiences().gsonSerializer();
String messageSystem = this.carbonChat.getConfig().getString("message-system", "none");
if (messageSystem == null) {
messageSystem = "none";
}
switch (messageSystem.toLowerCase()) {
case "bungee":
this.carbonChat.getLogger().info("Using Bungee Plugin Messaging for message forwarding!");
this.messageService = new BungeeMessageService(this.carbonChat);
break;
case "redis":
this.carbonChat.getLogger().info("Using Redis for message forwarding!");
this.messageService = new RedisMessageService(this.carbonChat);
break;
case "none":
this.messageService = new EmptyMessageService();
break;
default:
this.carbonChat.getLogger().info("Invalid message service selected! Disabling syncing until next restart!");
this.messageService = new EmptyMessageService();
break;
}
this.messageService = messageService;
this.gsonSerializer = this.carbonChat.messageProcessor().audiences().gsonSerializer();
this.registerDefaultListeners();
}
@@ -63,33 +35,21 @@ public class MessageManager {
private void registerDefaultListeners() {
this.messageService().registerUserMessageListener("nickname", (user, byteArray) -> {
final String nickname = byteArray.readUTF();
final String message = this.carbonChat.translations().nicknameSet();
user.nickname(nickname, true);
final Player player = Bukkit.getPlayer(user.uuid());
if (player != null) {
final String message = this.carbonChat.language().getString("nickname-set");
user.sendMessage(this.carbonChat.adventureManager().processMessageWithPapi(player,
message, "nickname", nickname));
}
user.sendMessage(this.carbonChat.messageProcessor().processMessage(message, "nickname", nickname));
});
this.messageService().registerUserMessageListener("nickname-reset", (user, byteArray) -> {
final String message = this.carbonChat.translations().nicknameReset();
user.nickname(null, true);
final Player player = Bukkit.getPlayer(user.uuid());
if (player != null) {
final String message = this.carbonChat.language().getString("nickname-reset");
user.sendMessage(this.carbonChat.adventureManager().processMessageWithPapi(player, message));
}
user.sendMessage(this.carbonChat.messageProcessor().processMessage(message));
});
this.messageService().registerUserMessageListener("selected-channel", (user, byteArray) -> {
user.selectedChannel(this.carbonChat.channelManager().registry().get(byteArray.readUTF()), true);
user.selectedChannel(this.carbonChat.channelRegistry().get(byteArray.readUTF()), true);
});
this.messageService().registerUserMessageListener("spying-whispers", (user, byteArray) -> {
@@ -113,27 +73,27 @@ public class MessageManager {
});
this.messageService().registerUserMessageListener("ignoring-channel", (user, byteArray) -> {
user.channelSettings(this.carbonChat.channelManager().registry().get(byteArray.readUTF()))
user.channelSettings(this.carbonChat.channelRegistry().get(byteArray.readUTF()))
.ignoring(byteArray.readBoolean(), true);
});
this.messageService().registerUserMessageListener("spying-channel", (user, byteArray) -> {
user.channelSettings(this.carbonChat.channelManager().registry().get(byteArray.readUTF()))
user.channelSettings(this.carbonChat.channelRegistry().get(byteArray.readUTF()))
.spying(byteArray.readBoolean(), true);
});
this.messageService().registerUserMessageListener("channel-color", (user, byteArray) -> {
user.channelSettings(this.carbonChat.channelManager().registry().get(byteArray.readUTF()))
user.channelSettings(this.carbonChat.channelRegistry().get(byteArray.readUTF()))
.color(TextColor.fromHexString(byteArray.readUTF()), true);
});
this.messageService().registerUserMessageListener("channel-color-reset", (user, byteArray) -> {
user.channelSettings(this.carbonChat.channelManager().registry().get(byteArray.readUTF()))
user.channelSettings(this.carbonChat.channelRegistry().get(byteArray.readUTF()))
.color(null, true);
});
this.messageService().registerUUIDMessageListener("channel-component", (uuid, byteArray) -> {
final ChatChannel channel = this.carbonChat.channelManager().registry().get(byteArray.readUTF());
final ChatChannel channel = this.carbonChat.channelRegistry().get(byteArray.readUTF());
final ChatUser user = this.carbonChat.userService().wrap(uuid);
if (channel != null) {
@@ -141,7 +101,7 @@ public class MessageManager {
channel.sendComponent(user, component);
this.carbonChat.adventureManager().audiences().console().sendMessage(component);
this.carbonChat.messageProcessor().audiences().console().sendMessage(component);
}
});
@@ -0,0 +1,36 @@
package net.draycia.carbon.common.messaging;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
public class RedisCredentials {
private final @NonNull String host;
private final @Nullable String password;
private final int port;
private final int database;
public RedisCredentials(final @NonNull String host, final @Nullable String password, final int port, final int database) {
this.host = host;
this.password = password;
this.port = port;
this.database = database;
}
public @NonNull String host() {
return this.host;
}
public @Nullable String password() {
return this.password;
}
public int port() {
return this.port;
}
public int database() {
return this.database;
}
}
@@ -1,4 +1,4 @@
package net.draycia.carbon.util;
package net.draycia.carbon.common.messaging;
import io.lettuce.core.pubsub.RedisPubSubListener;
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -1,4 +1,4 @@
package net.draycia.carbon.messaging.impl;
package net.draycia.carbon.common.messaging;
import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteArrayDataOutput;
@@ -7,10 +7,9 @@ import io.lettuce.core.RedisClient;
import io.lettuce.core.RedisURI;
import io.lettuce.core.pubsub.StatefulRedisPubSubConnection;
import io.lettuce.core.pubsub.api.sync.RedisPubSubCommands;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.api.CarbonChat;
import net.draycia.carbon.api.messaging.MessageService;
import net.draycia.carbon.api.users.ChatUser;
import net.draycia.carbon.util.RedisListener;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.Base64;
@@ -40,19 +39,14 @@ public class RedisMessageService implements MessageService {
@NonNull
private final CarbonChat carbonChat;
public RedisMessageService(@NonNull final CarbonChat carbonChat) {
public RedisMessageService(@NonNull final CarbonChat carbonChat, @NonNull final RedisCredentials credentials) {
this.carbonChat = carbonChat;
final String host = this.carbonChat.getConfig().getString("redis.host");
final String password = this.carbonChat.getConfig().getString("redis.password");
final int port = this.carbonChat.getConfig().getInt("redis.port");
final int database = this.carbonChat.getConfig().getInt("redis.database");
final RedisURI.Builder builder = RedisURI.Builder.redis(credentials.host(), credentials.port())
.withDatabase(credentials.database());
final RedisURI.Builder builder = RedisURI.Builder.redis(host, port)
.withDatabase(database);
if (password != null) {
builder.withPassword(password.toCharArray());
if (credentials.password() != null) {
builder.withPassword(credentials.password().toCharArray());
}
final RedisClient client = RedisClient.create(builder.build());
+40 -10
View File
@@ -1,9 +1,4 @@
plugins {
id 'checkstyle'
id 'java'
id 'java-library'
id 'maven'
id 'maven-publish'
id 'com.palantir.git-version' version '0.12.3'
id 'org.checkerframework' version '0.5.9'
}
@@ -16,12 +11,45 @@ group = 'net.draycia'
description = 'CarbonChat'
version = project.property('projectVersion') + '-' + gitHash
checkstyle {
def configRoot = new File(rootProject.projectDir, '.checkstyle')
toolVersion = '8.34'
configDirectory = configRoot
configProperties = [basedir: configRoot.getAbsolutePath()]
subprojects {
apply plugin: 'checkstyle'
apply plugin: 'java'
apply plugin: 'java-library'
apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: 'org.checkerframework'
repositories {
mavenLocal()
mavenCentral()
maven { url = 'https://repo.maven.apache.org/maven2' }
maven { url = 'https://oss.sonatype.org/content/groups/public/' }
maven { url = 'https://maven.enginehub.org/repo/' }
maven { url = 'https://papermc.io/repo/repository/maven-public/' }
maven { url = 'https://repo.extendedclip.com/content/repositories/placeholderapi/' }
maven { url = 'https://jitpack.io' }
maven { url = 'https://dl.bintray.com/ichbinjoe/public/' }
maven { url = 'https://repo.codemc.org/repository/maven-public/' }
maven { url = "https://repo.aikar.co/content/groups/aikar/" }
maven { url = 'https://raw.githubusercontent.com/JorelAli/CommandAPI/mvn-repo/' }
maven { url = 'https://repo.minebench.de/' }
}
dependencies {
checkstyle("ca.stellardrift:stylecheck:0.1-SNAPSHOT")
}
checkstyle {
def configRoot = new File(rootProject.projectDir, '.checkstyle')
toolVersion = '8.34'
configDirectory = configRoot
configProperties = [basedir: configRoot.getAbsolutePath()]
}
sourceCompatibility = '1.8'
}
<<<<<<< HEAD
repositories {
mavenLocal()
@@ -47,3 +75,5 @@ dependencies {
}
sourceCompatibility = '1.8'
=======
>>>>>>> Progress on CarbonChat-Common
+1
View File
@@ -1,3 +1,4 @@
include 'CarbonChat-API'
include 'CarbonChat-Common'
include 'CarbonChat-Bukkit'