Initial commit for messages config

This commit is contained in:
Vankka 2023-07-18 23:51:20 +03:00
parent 3c71ade347
commit e2143f0cc1
No known key found for this signature in database
GPG Key ID: 6E50CB7A29B96AD0
19 changed files with 264 additions and 26 deletions

View File

@ -26,6 +26,7 @@ import com.discordsrv.bukkit.config.connection.BukkitConnectionConfig;
import com.discordsrv.bukkit.config.main.BukkitConfig; import com.discordsrv.bukkit.config.main.BukkitConfig;
import com.discordsrv.bukkit.config.manager.BukkitConfigManager; import com.discordsrv.bukkit.config.manager.BukkitConfigManager;
import com.discordsrv.bukkit.config.manager.BukkitConnectionConfigManager; import com.discordsrv.bukkit.config.manager.BukkitConnectionConfigManager;
import com.discordsrv.bukkit.config.manager.BukkitMessagesConfigManager;
import com.discordsrv.bukkit.console.BukkitConsole; import com.discordsrv.bukkit.console.BukkitConsole;
import com.discordsrv.bukkit.listener.BukkitConnectionListener; import com.discordsrv.bukkit.listener.BukkitConnectionListener;
import com.discordsrv.bukkit.listener.BukkitDeathListener; import com.discordsrv.bukkit.listener.BukkitDeathListener;
@ -43,6 +44,8 @@ import com.discordsrv.common.ServerDiscordSRV;
import com.discordsrv.common.command.game.handler.ICommandHandler; import com.discordsrv.common.command.game.handler.ICommandHandler;
import com.discordsrv.common.config.configurate.manager.ConnectionConfigManager; import com.discordsrv.common.config.configurate.manager.ConnectionConfigManager;
import com.discordsrv.common.config.configurate.manager.MainConfigManager; import com.discordsrv.common.config.configurate.manager.MainConfigManager;
import com.discordsrv.common.config.configurate.manager.MessagesConfigManager;
import com.discordsrv.common.config.messages.MessagesConfig;
import com.discordsrv.common.debug.data.OnlineMode; import com.discordsrv.common.debug.data.OnlineMode;
import com.discordsrv.common.messageforwarding.game.minecrafttodiscord.MinecraftToDiscordChatModule; import com.discordsrv.common.messageforwarding.game.minecrafttodiscord.MinecraftToDiscordChatModule;
import com.discordsrv.common.plugin.PluginManager; import com.discordsrv.common.plugin.PluginManager;
@ -56,7 +59,7 @@ import java.lang.reflect.Field;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
public class BukkitDiscordSRV extends ServerDiscordSRV<DiscordSRVBukkitBootstrap, BukkitConfig, BukkitConnectionConfig> { public class BukkitDiscordSRV extends ServerDiscordSRV<DiscordSRVBukkitBootstrap, BukkitConfig, BukkitConnectionConfig, MessagesConfig> {
private BukkitAudiences audiences; private BukkitAudiences audiences;
private BukkitTranslationLoader translationLoader; private BukkitTranslationLoader translationLoader;
@ -71,6 +74,7 @@ public class BukkitDiscordSRV extends ServerDiscordSRV<DiscordSRVBukkitBootstrap
private final BukkitConnectionConfigManager connectionConfigManager; private final BukkitConnectionConfigManager connectionConfigManager;
private final BukkitConfigManager configManager; private final BukkitConfigManager configManager;
private final BukkitMessagesConfigManager messagesConfigManager;
private static IBukkitScheduler createScheduler(BukkitDiscordSRV discordSRV) { private static IBukkitScheduler createScheduler(BukkitDiscordSRV discordSRV) {
try { try {
@ -92,6 +96,7 @@ public class BukkitDiscordSRV extends ServerDiscordSRV<DiscordSRVBukkitBootstrap
// Config // Config
this.connectionConfigManager = new BukkitConnectionConfigManager(this); this.connectionConfigManager = new BukkitConnectionConfigManager(this);
this.configManager = new BukkitConfigManager(this); this.configManager = new BukkitConfigManager(this);
this.messagesConfigManager = new BukkitMessagesConfigManager(this);
load(); load();
@ -170,6 +175,11 @@ public class BukkitDiscordSRV extends ServerDiscordSRV<DiscordSRVBukkitBootstrap
return configManager; return configManager;
} }
@Override
public MessagesConfigManager<MessagesConfig> messagesConfigManager() {
return messagesConfigManager;
}
@Override @Override
protected void enable() throws Throwable { protected void enable() throws Throwable {
// Service provider // Service provider

View File

@ -0,0 +1,17 @@
package com.discordsrv.bukkit.config.manager;
import com.discordsrv.common.DiscordSRV;
import com.discordsrv.common.config.configurate.manager.MessagesConfigManager;
import com.discordsrv.common.config.messages.MessagesConfig;
public class BukkitMessagesConfigManager extends MessagesConfigManager<MessagesConfig> {
public BukkitMessagesConfigManager(DiscordSRV discordSRV) {
super(discordSRV);
}
@Override
public MessagesConfig createConfiguration() {
return new MessagesConfig();
}
}

View File

@ -24,10 +24,12 @@ import com.discordsrv.bungee.player.BungeePlayerProvider;
import com.discordsrv.bungee.plugin.BungeePluginManager; import com.discordsrv.bungee.plugin.BungeePluginManager;
import com.discordsrv.common.ProxyDiscordSRV; import com.discordsrv.common.ProxyDiscordSRV;
import com.discordsrv.common.command.game.handler.ICommandHandler; import com.discordsrv.common.command.game.handler.ICommandHandler;
import com.discordsrv.common.config.configurate.manager.MessagesConfigManager;
import com.discordsrv.common.config.connection.ConnectionConfig; import com.discordsrv.common.config.connection.ConnectionConfig;
import com.discordsrv.common.config.main.MainConfig; import com.discordsrv.common.config.main.MainConfig;
import com.discordsrv.common.config.configurate.manager.ConnectionConfigManager; import com.discordsrv.common.config.configurate.manager.ConnectionConfigManager;
import com.discordsrv.common.config.configurate.manager.MainConfigManager; import com.discordsrv.common.config.configurate.manager.MainConfigManager;
import com.discordsrv.common.config.messages.MessagesConfig;
import com.discordsrv.common.debug.data.OnlineMode; import com.discordsrv.common.debug.data.OnlineMode;
import com.discordsrv.common.plugin.PluginManager; import com.discordsrv.common.plugin.PluginManager;
import com.discordsrv.common.scheduler.StandardScheduler; import com.discordsrv.common.scheduler.StandardScheduler;
@ -36,7 +38,7 @@ import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.plugin.Plugin; import net.md_5.bungee.api.plugin.Plugin;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public class BungeeDiscordSRV extends ProxyDiscordSRV<DiscordSRVBungeeBootstrap, MainConfig, ConnectionConfig> { public class BungeeDiscordSRV extends ProxyDiscordSRV<DiscordSRVBungeeBootstrap, MainConfig, ConnectionConfig, MessagesConfig> {
private BungeeAudiences audiences; private BungeeAudiences audiences;
@ -109,6 +111,11 @@ public class BungeeDiscordSRV extends ProxyDiscordSRV<DiscordSRVBungeeBootstrap,
return null; return null;
} }
@Override
public MessagesConfigManager<MessagesConfig> messagesConfigManager() {
return null;
}
@Override @Override
protected void enable() throws Throwable { protected void enable() throws Throwable {
// Player related // Player related

View File

@ -33,12 +33,15 @@ import com.discordsrv.common.command.discord.DiscordCommandModule;
import com.discordsrv.common.command.game.GameCommandModule; import com.discordsrv.common.command.game.GameCommandModule;
import com.discordsrv.common.command.game.commands.subcommand.reload.ReloadResults; import com.discordsrv.common.command.game.commands.subcommand.reload.ReloadResults;
import com.discordsrv.common.component.ComponentFactory; import com.discordsrv.common.component.ComponentFactory;
import com.discordsrv.common.config.configurate.manager.ConnectionConfigManager;
import com.discordsrv.common.config.configurate.manager.MainConfigManager;
import com.discordsrv.common.config.configurate.manager.MessagesConfigManager;
import com.discordsrv.common.config.configurate.manager.MessagesConfigSingleManager;
import com.discordsrv.common.config.connection.ConnectionConfig; import com.discordsrv.common.config.connection.ConnectionConfig;
import com.discordsrv.common.config.connection.UpdateConfig; import com.discordsrv.common.config.connection.UpdateConfig;
import com.discordsrv.common.config.main.MainConfig; import com.discordsrv.common.config.main.MainConfig;
import com.discordsrv.common.config.main.linking.LinkedAccountConfig; import com.discordsrv.common.config.main.linking.LinkedAccountConfig;
import com.discordsrv.common.config.configurate.manager.ConnectionConfigManager; import com.discordsrv.common.config.messages.MessagesConfig;
import com.discordsrv.common.config.configurate.manager.MainConfigManager;
import com.discordsrv.common.debug.data.VersionInfo; import com.discordsrv.common.debug.data.VersionInfo;
import com.discordsrv.common.dependency.DiscordSRVDependencyManager; import com.discordsrv.common.dependency.DiscordSRVDependencyManager;
import com.discordsrv.common.discord.api.DiscordAPIEventModule; import com.discordsrv.common.discord.api.DiscordAPIEventModule;
@ -83,6 +86,7 @@ import okhttp3.ConnectionPool;
import okhttp3.Dispatcher; import okhttp3.Dispatcher;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
import okhttp3.Request; import okhttp3.Request;
import org.apache.commons.lang3.StringUtils;
import org.intellij.lang.annotations.Language; import org.intellij.lang.annotations.Language;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@ -109,7 +113,12 @@ import java.util.jar.Manifest;
* @param <C> the config type * @param <C> the config type
* @param <CC> the connections config type * @param <CC> the connections config type
*/ */
public abstract class AbstractDiscordSRV<B extends IBootstrap, C extends MainConfig, CC extends ConnectionConfig> implements DiscordSRV { public abstract class AbstractDiscordSRV<
B extends IBootstrap,
C extends MainConfig,
CC extends ConnectionConfig,
MC extends MessagesConfig
> implements DiscordSRV {
private final AtomicReference<Status> status = new AtomicReference<>(Status.INITIALIZED); private final AtomicReference<Status> status = new AtomicReference<>(Status.INITIALIZED);
private final AtomicReference<Boolean> beenReady = new AtomicReference<>(false); private final AtomicReference<Boolean> beenReady = new AtomicReference<>(false);
@ -379,6 +388,21 @@ public abstract class AbstractDiscordSRV<B extends IBootstrap, C extends MainCon
return configManager().config(); return configManager().config();
} }
@Override
public abstract MessagesConfigManager<MC> messagesConfigManager();
@Override
public MC messagesConfig(Locale locale) {
MessagesConfigSingleManager<MC> manager = messagesConfigManager().getManager(locale);
if (manager == null) {
manager = messagesConfigManager().getManager(defaultLocale());
}
if (manager == null) {
manager = messagesConfigManager().getManager(Locale.US);
}
return manager.config();
}
// Module // Module
@Override @Override
@ -429,8 +453,19 @@ public abstract class AbstractDiscordSRV<B extends IBootstrap, C extends MainCon
} }
@Override @Override
public Locale locale() { public Locale defaultLocale() {
// TODO: config MainConfig config = config();
if (config != null) {
String defaultLanguage = config.messages.defaultLanguage;
if (StringUtils.isBlank(defaultLanguage)) {
for (Locale locale : Locale.getAvailableLocales()) {
if (locale.getISO3Language().equals(defaultLanguage)) {
return locale;
}
}
}
}
return Locale.getDefault(); return Locale.getDefault();
} }
@ -602,6 +637,7 @@ public abstract class AbstractDiscordSRV<B extends IBootstrap, C extends MainCon
try { try {
connectionConfigManager().load(); connectionConfigManager().load();
configManager().load(); configManager().load();
messagesConfigManager().load();
channelConfig().reload(); channelConfig().reload();
} catch (Throwable t) { } catch (Throwable t) {

View File

@ -26,10 +26,12 @@ import com.discordsrv.common.channel.ChannelConfigHelper;
import com.discordsrv.common.command.game.GameCommandExecutionHelper; import com.discordsrv.common.command.game.GameCommandExecutionHelper;
import com.discordsrv.common.command.game.handler.ICommandHandler; import com.discordsrv.common.command.game.handler.ICommandHandler;
import com.discordsrv.common.component.ComponentFactory; import com.discordsrv.common.component.ComponentFactory;
import com.discordsrv.common.config.connection.ConnectionConfig;
import com.discordsrv.common.config.main.MainConfig;
import com.discordsrv.common.config.configurate.manager.ConnectionConfigManager; import com.discordsrv.common.config.configurate.manager.ConnectionConfigManager;
import com.discordsrv.common.config.configurate.manager.MainConfigManager; import com.discordsrv.common.config.configurate.manager.MainConfigManager;
import com.discordsrv.common.config.configurate.manager.MessagesConfigManager;
import com.discordsrv.common.config.connection.ConnectionConfig;
import com.discordsrv.common.config.main.MainConfig;
import com.discordsrv.common.config.messages.MessagesConfig;
import com.discordsrv.common.console.Console; import com.discordsrv.common.console.Console;
import com.discordsrv.common.debug.data.OnlineMode; import com.discordsrv.common.debug.data.OnlineMode;
import com.discordsrv.common.debug.data.VersionInfo; import com.discordsrv.common.debug.data.VersionInfo;
@ -115,6 +117,9 @@ public interface DiscordSRV extends DiscordSRVApi {
ConnectionConfig connectionConfig(); ConnectionConfig connectionConfig();
MainConfigManager<? extends MainConfig> configManager(); MainConfigManager<? extends MainConfig> configManager();
MainConfig config(); MainConfig config();
MessagesConfigManager<? extends MessagesConfig> messagesConfigManager();
MessagesConfig messagesConfig(Locale locale);
// Config helper // Config helper
ChannelConfigHelper channelConfig(); ChannelConfigHelper channelConfig();
@ -130,7 +135,7 @@ public interface DiscordSRV extends DiscordSRVApi {
void unregisterModule(AbstractModule<?> module); void unregisterModule(AbstractModule<?> module);
ModuleManager moduleManager(); ModuleManager moduleManager();
Locale locale(); Locale defaultLocale();
// Status // Status
void setStatus(Status status); void setStatus(Status status);

View File

@ -21,9 +21,15 @@ package com.discordsrv.common;
import com.discordsrv.common.bootstrap.IBootstrap; import com.discordsrv.common.bootstrap.IBootstrap;
import com.discordsrv.common.config.connection.ConnectionConfig; import com.discordsrv.common.config.connection.ConnectionConfig;
import com.discordsrv.common.config.main.MainConfig; import com.discordsrv.common.config.main.MainConfig;
import com.discordsrv.common.config.messages.MessagesConfig;
import com.discordsrv.common.messageforwarding.game.ServerSwitchMessageModule; import com.discordsrv.common.messageforwarding.game.ServerSwitchMessageModule;
public abstract class ProxyDiscordSRV<B extends IBootstrap, C extends MainConfig, CC extends ConnectionConfig> extends AbstractDiscordSRV<B, C, CC> { public abstract class ProxyDiscordSRV<
B extends IBootstrap,
C extends MainConfig,
CC extends ConnectionConfig,
MC extends MessagesConfig
> extends AbstractDiscordSRV<B, C, CC, MC> {
public ProxyDiscordSRV(B bootstrap) { public ProxyDiscordSRV(B bootstrap) {
super(bootstrap); super(bootstrap);

View File

@ -21,6 +21,7 @@ package com.discordsrv.common;
import com.discordsrv.common.bootstrap.IBootstrap; import com.discordsrv.common.bootstrap.IBootstrap;
import com.discordsrv.common.config.connection.ConnectionConfig; import com.discordsrv.common.config.connection.ConnectionConfig;
import com.discordsrv.common.config.main.MainConfig; import com.discordsrv.common.config.main.MainConfig;
import com.discordsrv.common.config.messages.MessagesConfig;
import com.discordsrv.common.messageforwarding.game.AwardMessageModule; import com.discordsrv.common.messageforwarding.game.AwardMessageModule;
import com.discordsrv.common.messageforwarding.game.DeathMessageModule; import com.discordsrv.common.messageforwarding.game.DeathMessageModule;
import com.discordsrv.common.player.ServerPlayerProvider; import com.discordsrv.common.player.ServerPlayerProvider;
@ -30,7 +31,12 @@ import org.jetbrains.annotations.NotNull;
import javax.annotation.OverridingMethodsMustInvokeSuper; import javax.annotation.OverridingMethodsMustInvokeSuper;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
public abstract class ServerDiscordSRV<B extends IBootstrap, C extends MainConfig, CC extends ConnectionConfig> extends AbstractDiscordSRV<B, C, CC> { public abstract class ServerDiscordSRV<
B extends IBootstrap,
C extends MainConfig,
CC extends ConnectionConfig,
MC extends MessagesConfig
> extends AbstractDiscordSRV<B, C, CC, MC> {
public ServerDiscordSRV(B bootstrap) { public ServerDiscordSRV(B bootstrap) {
super(bootstrap); super(bootstrap);

View File

@ -0,0 +1,30 @@
package com.discordsrv.common.config.configurate.manager;
import com.discordsrv.common.DiscordSRV;
import com.discordsrv.common.config.messages.MessagesConfig;
import com.discordsrv.common.exception.ConfigException;
import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;
public abstract class MessagesConfigManager<C extends MessagesConfig> {
public Map<String, MessagesConfigSingleManager<C>> configs = new LinkedHashMap<>();
public MessagesConfigManager(DiscordSRV discordSRV) {
configs.put(Locale.US.getISO3Language(), new MessagesConfigSingleManager<>(discordSRV, this, Locale.US));
}
public abstract C createConfiguration();
public MessagesConfigSingleManager<C> getManager(Locale locale) {
return configs.get(locale.getISO3Language());
}
public void load() throws ConfigException {
for (Map.Entry<String, MessagesConfigSingleManager<C>> entry : configs.entrySet()) {
entry.getValue().load();
}
}
}

View File

@ -0,0 +1,44 @@
package com.discordsrv.common.config.configurate.manager;
import com.discordsrv.common.DiscordSRV;
import com.discordsrv.common.config.configurate.manager.abstraction.TranslatedConfigManager;
import com.discordsrv.common.config.configurate.manager.loader.YamlConfigLoaderProvider;
import com.discordsrv.common.config.messages.MessagesConfig;
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
import java.nio.file.Paths;
import java.util.Locale;
public class MessagesConfigSingleManager<C extends MessagesConfig>
extends TranslatedConfigManager<C, YamlConfigurationLoader>
implements YamlConfigLoaderProvider {
private final MessagesConfigManager<C> aggregateManager;
private final Locale locale;
protected MessagesConfigSingleManager(DiscordSRV discordSRV, MessagesConfigManager<C> aggregateManager, Locale locale) {
super(discordSRV);
this.aggregateManager = aggregateManager;
this.locale = locale;
}
@Override
protected String fileName() {
boolean multiple = discordSRV.config().messages.multiple;
if (multiple) {
return Paths.get("messages", locale.getISO3Language() + ".yaml").toString();
}
return MessagesConfig.FILE_NAME;
}
@Override
public Locale locale() {
return locale;
}
@Override
public C createConfiguration() {
return aggregateManager.createConfiguration();
}
}

View File

@ -69,26 +69,30 @@ public abstract class ConfigurateConfigManager<T, LT extends AbstractConfigurati
}; };
protected final DiscordSRV discordSRV; protected final DiscordSRV discordSRV;
private final Path filePath;
private final ObjectMapper.Factory objectMapper; private final ObjectMapper.Factory objectMapper;
private final ObjectMapper.Factory cleanObjectMapper; private final ObjectMapper.Factory cleanObjectMapper;
private final LT loader; private Path filePath;
private LT loader;
protected T configuration; protected T configuration;
public ConfigurateConfigManager(DiscordSRV discordSRV) { public ConfigurateConfigManager(DiscordSRV discordSRV) {
this.discordSRV = discordSRV; this.discordSRV = discordSRV;
this.filePath = discordSRV.dataDirectory().resolve(fileName());
this.objectMapper = objectMapperBuilder().build(); this.objectMapper = objectMapperBuilder().build();
this.cleanObjectMapper = cleanObjectMapperBuilder().build(); this.cleanObjectMapper = cleanObjectMapperBuilder().build();
this.loader = createLoader(filePath, nodeOptions());
} }
public Path filePath() { public Path filePath() {
if (filePath == null) {
filePath = discordSRV.dataDirectory().resolve(fileName());
}
return filePath; return filePath;
} }
public LT loader() { public LT loader() {
if (loader == null) {
loader = createLoader(filePath(), nodeOptions());
}
return loader; return loader;
} }
@ -310,6 +314,7 @@ public abstract class ConfigurateConfigManager<T, LT extends AbstractConfigurati
@Override @Override
public void save() throws ConfigException { public void save() throws ConfigException {
try { try {
LT loader = loader();
CommentedConfigurationNode node = loader.createNode(); CommentedConfigurationNode node = loader.createNode();
save(configuration, (Class<T>) configuration.getClass(), node); save(configuration, (Class<T>) configuration.getClass(), node);
loader.save(node); loader.save(node);

View File

@ -35,6 +35,7 @@ import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Locale;
public abstract class TranslatedConfigManager<T extends Config, LT extends AbstractConfigurationLoader<CommentedConfigurationNode>> public abstract class TranslatedConfigManager<T extends Config, LT extends AbstractConfigurationLoader<CommentedConfigurationNode>>
extends ConfigurateConfigManager<T, LT> { extends ConfigurateConfigManager<T, LT> {
@ -45,6 +46,10 @@ public abstract class TranslatedConfigManager<T extends Config, LT extends Abstr
super(discordSRV); super(discordSRV);
} }
public Locale locale() {
return discordSRV.defaultLocale();
}
@Override @Override
public void load() throws ConfigException { public void load() throws ConfigException {
super.reload(); super.reload();
@ -100,9 +105,12 @@ public abstract class TranslatedConfigManager<T extends Config, LT extends Abstr
} }
private ConfigurationNode getTranslationRoot() throws ConfigurateException { private ConfigurationNode getTranslationRoot() throws ConfigurateException {
String languageCode = discordSRV.locale().getISO3Language(); String languageCode = locale().getISO3Language();
URL resourceURL = discordSRV.getClass().getClassLoader() ClassLoader classLoader = discordSRV.getClass().getClassLoader();
.getResource("translations/" + languageCode + ".yml"); URL resourceURL = classLoader.getResource("translations/" + languageCode + ".yaml");
if (resourceURL == null) {
resourceURL = classLoader.getResource("translations/eng.yaml");
}
if (resourceURL == null) { if (resourceURL == null) {
return null; return null;
} }

View File

@ -87,6 +87,8 @@ public abstract class MainConfig implements Config {
@Comment("Configuration for the %discord_invite% placeholder. The below options will be attempted in the order they are in") @Comment("Configuration for the %discord_invite% placeholder. The below options will be attempted in the order they are in")
public DiscordInviteConfig invite = new DiscordInviteConfig(); public DiscordInviteConfig invite = new DiscordInviteConfig();
public MessagesMainConfig messages = new MessagesMainConfig();
@Order(10) // To go below required linking config @ 5 @Order(10) // To go below required linking config @ 5
@Comment("Configuration for the %player_avatar_url% placeholder") @Comment("Configuration for the %player_avatar_url% placeholder")
public AvatarProviderConfig avatarProvider = new AvatarProviderConfig(); public AvatarProviderConfig avatarProvider = new AvatarProviderConfig();

View File

@ -0,0 +1,14 @@
package com.discordsrv.common.config.main;
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
import org.spongepowered.configurate.objectmapping.meta.Comment;
@ConfigSerializable
public class MessagesMainConfig {
@Comment("If there should be multiple messages files, one for every language")
public boolean multiple = false;
@Comment("The 3 letter ISO 639-2 code for the default language, if left blank the system default will be used")
public String defaultLanguage = "eng";
}

View File

@ -0,0 +1,18 @@
package com.discordsrv.common.config.messages;
import com.discordsrv.common.config.Config;
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
@ConfigSerializable
public class MessagesConfig implements Config {
public static final String FILE_NAME = "messages.yaml";
@Override
public final String getFileName() {
return FILE_NAME;
}
public String testOption = "test option";
}

View File

@ -31,6 +31,7 @@ import com.discordsrv.api.discord.events.message.DiscordMessageDeleteEvent;
import com.discordsrv.api.discord.events.message.DiscordMessageReceiveEvent; import com.discordsrv.api.discord.events.message.DiscordMessageReceiveEvent;
import com.discordsrv.api.discord.events.message.DiscordMessageUpdateEvent; import com.discordsrv.api.discord.events.message.DiscordMessageUpdateEvent;
import com.discordsrv.api.event.bus.Subscribe; import com.discordsrv.api.event.bus.Subscribe;
import com.discordsrv.api.event.events.message.forward.discord.DiscordChatMessageForwardedEvent;
import com.discordsrv.api.event.events.message.receive.discord.DiscordChatMessageProcessEvent; import com.discordsrv.api.event.events.message.receive.discord.DiscordChatMessageProcessEvent;
import com.discordsrv.api.event.events.message.receive.discord.DiscordChatMessageReceiveEvent; import com.discordsrv.api.event.events.message.receive.discord.DiscordChatMessageReceiveEvent;
import com.discordsrv.api.placeholder.util.Placeholders; import com.discordsrv.api.placeholder.util.Placeholders;
@ -203,6 +204,7 @@ public class DiscordChatMessageModule extends AbstractModule<DiscordSRV> {
} }
gameChannel.sendMessage(component); gameChannel.sendMessage(component);
discordSRV.eventBus().publish(new DiscordChatMessageForwardedEvent(component, gameChannel));
} }
public static class MessageSend { public static class MessageSend {

View File

@ -21,12 +21,14 @@ package com.discordsrv.common;
import com.discordsrv.common.bootstrap.IBootstrap; import com.discordsrv.common.bootstrap.IBootstrap;
import com.discordsrv.common.bootstrap.LifecycleManager; import com.discordsrv.common.bootstrap.LifecycleManager;
import com.discordsrv.common.command.game.handler.ICommandHandler; import com.discordsrv.common.command.game.handler.ICommandHandler;
import com.discordsrv.common.config.configurate.manager.ConnectionConfigManager;
import com.discordsrv.common.config.configurate.manager.MainConfigManager;
import com.discordsrv.common.config.configurate.manager.MessagesConfigManager;
import com.discordsrv.common.config.configurate.manager.abstraction.ServerConfigManager;
import com.discordsrv.common.config.connection.ConnectionConfig; import com.discordsrv.common.config.connection.ConnectionConfig;
import com.discordsrv.common.config.main.MainConfig; import com.discordsrv.common.config.main.MainConfig;
import com.discordsrv.common.config.main.PluginIntegrationConfig; import com.discordsrv.common.config.main.PluginIntegrationConfig;
import com.discordsrv.common.config.configurate.manager.ConnectionConfigManager; import com.discordsrv.common.config.messages.MessagesConfig;
import com.discordsrv.common.config.configurate.manager.MainConfigManager;
import com.discordsrv.common.config.configurate.manager.abstraction.ServerConfigManager;
import com.discordsrv.common.console.Console; import com.discordsrv.common.console.Console;
import com.discordsrv.common.debug.data.OnlineMode; import com.discordsrv.common.debug.data.OnlineMode;
import com.discordsrv.common.logging.Logger; import com.discordsrv.common.logging.Logger;
@ -44,7 +46,7 @@ import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
@SuppressWarnings("ConstantConditions") @SuppressWarnings("ConstantConditions")
public class MockDiscordSRV extends AbstractDiscordSRV<IBootstrap, MainConfig, ConnectionConfig> { public class MockDiscordSRV extends AbstractDiscordSRV<IBootstrap, MainConfig, ConnectionConfig, MessagesConfig> {
public static final MockDiscordSRV INSTANCE = new MockDiscordSRV(); public static final MockDiscordSRV INSTANCE = new MockDiscordSRV();
@ -148,6 +150,11 @@ public class MockDiscordSRV extends AbstractDiscordSRV<IBootstrap, MainConfig, C
}; };
} }
@Override
public MessagesConfigManager<MessagesConfig> messagesConfigManager() {
return null;
}
@Override @Override
public void waitForStatus(Status status) throws InterruptedException { public void waitForStatus(Status status) throws InterruptedException {
super.waitForStatus(status); super.waitForStatus(status);

View File

@ -22,10 +22,12 @@ import com.discordsrv.common.AbstractDiscordSRV;
import com.discordsrv.common.bootstrap.IBootstrap; import com.discordsrv.common.bootstrap.IBootstrap;
import com.discordsrv.common.bootstrap.LifecycleManager; import com.discordsrv.common.bootstrap.LifecycleManager;
import com.discordsrv.common.command.game.handler.ICommandHandler; import com.discordsrv.common.command.game.handler.ICommandHandler;
import com.discordsrv.common.config.configurate.manager.MessagesConfigManager;
import com.discordsrv.common.config.connection.ConnectionConfig; import com.discordsrv.common.config.connection.ConnectionConfig;
import com.discordsrv.common.config.main.MainConfig; import com.discordsrv.common.config.main.MainConfig;
import com.discordsrv.common.config.configurate.manager.ConnectionConfigManager; import com.discordsrv.common.config.configurate.manager.ConnectionConfigManager;
import com.discordsrv.common.config.configurate.manager.MainConfigManager; import com.discordsrv.common.config.configurate.manager.MainConfigManager;
import com.discordsrv.common.config.messages.MessagesConfig;
import com.discordsrv.common.console.Console; import com.discordsrv.common.console.Console;
import com.discordsrv.common.debug.data.OnlineMode; import com.discordsrv.common.debug.data.OnlineMode;
import com.discordsrv.common.logging.Logger; import com.discordsrv.common.logging.Logger;
@ -40,7 +42,7 @@ import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
@SuppressWarnings("ConstantConditions") @SuppressWarnings("ConstantConditions")
public class MockDiscordSRV extends AbstractDiscordSRV<IBootstrap, MainConfig, ConnectionConfig> { public class MockDiscordSRV extends AbstractDiscordSRV<IBootstrap, MainConfig, ConnectionConfig, MessagesConfig> {
public MockDiscordSRV() { public MockDiscordSRV() {
super(new IBootstrap() { super(new IBootstrap() {
@ -115,4 +117,9 @@ public class MockDiscordSRV extends AbstractDiscordSRV<IBootstrap, MainConfig, C
public MainConfigManager<MainConfig> configManager() { public MainConfigManager<MainConfig> configManager() {
return null; return null;
} }
@Override
public MessagesConfigManager<MessagesConfig> messagesConfigManager() {
return null;
}
} }

View File

@ -21,10 +21,12 @@ package com.discordsrv.sponge;
import com.discordsrv.api.DiscordSRVApi; import com.discordsrv.api.DiscordSRVApi;
import com.discordsrv.common.ServerDiscordSRV; import com.discordsrv.common.ServerDiscordSRV;
import com.discordsrv.common.command.game.handler.ICommandHandler; import com.discordsrv.common.command.game.handler.ICommandHandler;
import com.discordsrv.common.config.configurate.manager.MessagesConfigManager;
import com.discordsrv.common.config.connection.ConnectionConfig; import com.discordsrv.common.config.connection.ConnectionConfig;
import com.discordsrv.common.config.main.MainConfig; import com.discordsrv.common.config.main.MainConfig;
import com.discordsrv.common.config.configurate.manager.ConnectionConfigManager; import com.discordsrv.common.config.configurate.manager.ConnectionConfigManager;
import com.discordsrv.common.config.configurate.manager.MainConfigManager; import com.discordsrv.common.config.configurate.manager.MainConfigManager;
import com.discordsrv.common.config.messages.MessagesConfig;
import com.discordsrv.common.debug.data.OnlineMode; import com.discordsrv.common.debug.data.OnlineMode;
import com.discordsrv.common.plugin.PluginManager; import com.discordsrv.common.plugin.PluginManager;
import com.discordsrv.sponge.console.SpongeConsole; import com.discordsrv.sponge.console.SpongeConsole;
@ -37,7 +39,7 @@ import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.lifecycle.ProvideServiceEvent; import org.spongepowered.api.event.lifecycle.ProvideServiceEvent;
import org.spongepowered.plugin.PluginContainer; import org.spongepowered.plugin.PluginContainer;
public class SpongeDiscordSRV extends ServerDiscordSRV<DiscordSRVSpongeBootstrap, MainConfig, ConnectionConfig> { public class SpongeDiscordSRV extends ServerDiscordSRV<DiscordSRVSpongeBootstrap, MainConfig, ConnectionConfig, MessagesConfig> {
private final SpongeScheduler scheduler; private final SpongeScheduler scheduler;
private final SpongeConsole console; private final SpongeConsole console;
@ -105,6 +107,11 @@ public class SpongeDiscordSRV extends ServerDiscordSRV<DiscordSRVSpongeBootstrap
return null; return null;
} }
@Override
public MessagesConfigManager<MessagesConfig> messagesConfigManager() {
return null;
}
@Override @Override
protected void enable() throws Throwable { protected void enable() throws Throwable {
// Service provider // Service provider

View File

@ -20,10 +20,12 @@ package com.discordsrv.velocity;
import com.discordsrv.common.ProxyDiscordSRV; import com.discordsrv.common.ProxyDiscordSRV;
import com.discordsrv.common.command.game.handler.ICommandHandler; import com.discordsrv.common.command.game.handler.ICommandHandler;
import com.discordsrv.common.config.configurate.manager.MessagesConfigManager;
import com.discordsrv.common.config.connection.ConnectionConfig; import com.discordsrv.common.config.connection.ConnectionConfig;
import com.discordsrv.common.config.main.MainConfig; import com.discordsrv.common.config.main.MainConfig;
import com.discordsrv.common.config.configurate.manager.ConnectionConfigManager; import com.discordsrv.common.config.configurate.manager.ConnectionConfigManager;
import com.discordsrv.common.config.configurate.manager.MainConfigManager; import com.discordsrv.common.config.configurate.manager.MainConfigManager;
import com.discordsrv.common.config.messages.MessagesConfig;
import com.discordsrv.common.debug.data.OnlineMode; import com.discordsrv.common.debug.data.OnlineMode;
import com.discordsrv.common.plugin.PluginManager; import com.discordsrv.common.plugin.PluginManager;
import com.discordsrv.common.scheduler.StandardScheduler; import com.discordsrv.common.scheduler.StandardScheduler;
@ -39,7 +41,7 @@ import java.net.URL;
import java.net.URLClassLoader; import java.net.URLClassLoader;
import java.util.jar.JarFile; import java.util.jar.JarFile;
public class VelocityDiscordSRV extends ProxyDiscordSRV<DiscordSRVVelocityBootstrap, MainConfig, ConnectionConfig> { public class VelocityDiscordSRV extends ProxyDiscordSRV<DiscordSRVVelocityBootstrap, MainConfig, ConnectionConfig, MessagesConfig> {
private final StandardScheduler scheduler; private final StandardScheduler scheduler;
private final VelocityConsole console; private final VelocityConsole console;
@ -121,6 +123,11 @@ public class VelocityDiscordSRV extends ProxyDiscordSRV<DiscordSRVVelocityBootst
return null; return null;
} }
@Override
public MessagesConfigManager<MessagesConfig> messagesConfigManager() {
return null;
}
@Override @Override
protected void enable() throws Throwable { protected void enable() throws Throwable {
super.enable(); super.enable();