From 4dc56a6aa42a95b30a38839aef03c5a4e35a7af2 Mon Sep 17 00:00:00 2001 From: Vankka Date: Wed, 19 Jul 2023 18:36:40 +0300 Subject: [PATCH] Fix :i18n module and get rid of MockDiscordSRV requirement --- .../config/manager/BukkitConfigManager.java | 6 + .../BukkitConnectionConfigManager.java | 6 + .../manager/ConnectionConfigManager.java | 6 + .../manager/MainConfigManager.java | 6 + .../abstraction/ConfigurateConfigManager.java | 24 ++-- .../abstraction/ServerConfigManager.java | 6 + .../abstraction/TranslatedConfigManager.java | 12 ++ .../config/DiscordSRVTranslation.java | 15 +-- .../com/discordsrv/config/MockDiscordSRV.java | 118 ------------------ .../config/TranslationConfigManagerProxy.java | 9 +- 10 files changed, 68 insertions(+), 140 deletions(-) delete mode 100644 i18n/src/main/java/com/discordsrv/config/MockDiscordSRV.java diff --git a/bukkit/src/main/java/com/discordsrv/bukkit/config/manager/BukkitConfigManager.java b/bukkit/src/main/java/com/discordsrv/bukkit/config/manager/BukkitConfigManager.java index dd7966f7..c79078cb 100644 --- a/bukkit/src/main/java/com/discordsrv/bukkit/config/manager/BukkitConfigManager.java +++ b/bukkit/src/main/java/com/discordsrv/bukkit/config/manager/BukkitConfigManager.java @@ -22,12 +22,18 @@ import com.discordsrv.bukkit.config.main.BukkitConfig; import com.discordsrv.common.DiscordSRV; import com.discordsrv.common.config.configurate.manager.abstraction.ServerConfigManager; +import java.nio.file.Path; + public class BukkitConfigManager extends ServerConfigManager { public BukkitConfigManager(DiscordSRV discordSRV) { super(discordSRV); } + public BukkitConfigManager(Path dataDirectory) { + super(dataDirectory); + } + @Override public BukkitConfig createConfiguration() { return new BukkitConfig(); diff --git a/bukkit/src/main/java/com/discordsrv/bukkit/config/manager/BukkitConnectionConfigManager.java b/bukkit/src/main/java/com/discordsrv/bukkit/config/manager/BukkitConnectionConfigManager.java index f6230cb0..ecc5f939 100644 --- a/bukkit/src/main/java/com/discordsrv/bukkit/config/manager/BukkitConnectionConfigManager.java +++ b/bukkit/src/main/java/com/discordsrv/bukkit/config/manager/BukkitConnectionConfigManager.java @@ -22,12 +22,18 @@ import com.discordsrv.bukkit.config.connection.BukkitConnectionConfig; import com.discordsrv.common.DiscordSRV; import com.discordsrv.common.config.configurate.manager.ConnectionConfigManager; +import java.nio.file.Path; + public class BukkitConnectionConfigManager extends ConnectionConfigManager { public BukkitConnectionConfigManager(DiscordSRV discordSRV) { super(discordSRV); } + public BukkitConnectionConfigManager(Path dataDirectory) { + super(dataDirectory); + } + @Override public BukkitConnectionConfig createConfiguration() { return new BukkitConnectionConfig(); diff --git a/common/src/main/java/com/discordsrv/common/config/configurate/manager/ConnectionConfigManager.java b/common/src/main/java/com/discordsrv/common/config/configurate/manager/ConnectionConfigManager.java index 6230d877..7d1c51e3 100644 --- a/common/src/main/java/com/discordsrv/common/config/configurate/manager/ConnectionConfigManager.java +++ b/common/src/main/java/com/discordsrv/common/config/configurate/manager/ConnectionConfigManager.java @@ -26,6 +26,8 @@ import org.spongepowered.configurate.ConfigurationOptions; import org.spongepowered.configurate.objectmapping.ObjectMapper; import org.spongepowered.configurate.yaml.YamlConfigurationLoader; +import java.nio.file.Path; + public abstract class ConnectionConfigManager extends TranslatedConfigManager implements YamlConfigLoaderProvider { @@ -34,6 +36,10 @@ public abstract class ConnectionConfigManager super(discordSRV); } + protected ConnectionConfigManager(Path dataDirectory) { + super(dataDirectory); + } + @Override public ConfigurationOptions configurationOptions(ObjectMapper.Factory objectMapper) { return super.configurationOptions(objectMapper) diff --git a/common/src/main/java/com/discordsrv/common/config/configurate/manager/MainConfigManager.java b/common/src/main/java/com/discordsrv/common/config/configurate/manager/MainConfigManager.java index 8189a170..a6a0b155 100644 --- a/common/src/main/java/com/discordsrv/common/config/configurate/manager/MainConfigManager.java +++ b/common/src/main/java/com/discordsrv/common/config/configurate/manager/MainConfigManager.java @@ -26,6 +26,8 @@ import org.spongepowered.configurate.ConfigurationOptions; import org.spongepowered.configurate.objectmapping.ObjectMapper; import org.spongepowered.configurate.yaml.YamlConfigurationLoader; +import java.nio.file.Path; + public abstract class MainConfigManager extends TranslatedConfigManager implements YamlConfigLoaderProvider { @@ -34,6 +36,10 @@ public abstract class MainConfigManager super(discordSRV); } + protected MainConfigManager(Path dataDirectory) { + super(dataDirectory); + } + @Override public ConfigurationOptions configurationOptions(ObjectMapper.Factory objectMapper) { return super.configurationOptions(objectMapper) diff --git a/common/src/main/java/com/discordsrv/common/config/configurate/manager/abstraction/ConfigurateConfigManager.java b/common/src/main/java/com/discordsrv/common/config/configurate/manager/abstraction/ConfigurateConfigManager.java index 3635aa3d..2da5526d 100644 --- a/common/src/main/java/com/discordsrv/common/config/configurate/manager/abstraction/ConfigurateConfigManager.java +++ b/common/src/main/java/com/discordsrv/common/config/configurate/manager/abstraction/ConfigurateConfigManager.java @@ -68,7 +68,6 @@ public abstract class ConfigurateConfigManager((FieldDiscoverer) FieldDiscoverer.emptyConstructorObject(), fieldOrder)) + .addDiscoverer(new OrderedFieldDiscovererProxy<>((FieldDiscoverer) FieldDiscoverer.record(), fieldOrder)); + } + + public ObjectMapper.Factory.Builder objectMapperBuilder() { + return commonObjectMapperBuilder() .addProcessor(Comment.class, (data, fieldType) -> { Processor processor = Processor.comments().make(data, fieldType); @@ -174,14 +183,7 @@ public abstract class ConfigurateConfigManager((FieldDiscoverer) FieldDiscoverer.emptyConstructorObject(), fieldOrder)) - .addDiscoverer(new OrderedFieldDiscovererProxy<>((FieldDiscoverer) FieldDiscoverer.record(), fieldOrder)); - } - - public ObjectMapper.Factory.Builder objectMapperBuilder() { - return commonObjectMapperBuilder(); + }); } protected ObjectMapper.Factory.Builder cleanObjectMapperBuilder() { diff --git a/common/src/main/java/com/discordsrv/common/config/configurate/manager/abstraction/ServerConfigManager.java b/common/src/main/java/com/discordsrv/common/config/configurate/manager/abstraction/ServerConfigManager.java index 7287e009..97f3fa84 100644 --- a/common/src/main/java/com/discordsrv/common/config/configurate/manager/abstraction/ServerConfigManager.java +++ b/common/src/main/java/com/discordsrv/common/config/configurate/manager/abstraction/ServerConfigManager.java @@ -26,12 +26,18 @@ import com.discordsrv.common.config.main.channels.base.server.ServerBaseChannelC import com.discordsrv.common.config.main.channels.base.server.ServerChannelConfig; import org.spongepowered.configurate.objectmapping.ObjectMapper; +import java.nio.file.Path; + public abstract class ServerConfigManager extends MainConfigManager { public ServerConfigManager(DiscordSRV discordSRV) { super(discordSRV); } + protected ServerConfigManager(Path dataDirectory) { + super(dataDirectory); + } + @Override public IChannelConfig.Serializer getChannelConfigSerializer(ObjectMapper.Factory mapperFactory) { return new IChannelConfig.Serializer(mapperFactory, ServerBaseChannelConfig.class, ServerChannelConfig.class); diff --git a/common/src/main/java/com/discordsrv/common/config/configurate/manager/abstraction/TranslatedConfigManager.java b/common/src/main/java/com/discordsrv/common/config/configurate/manager/abstraction/TranslatedConfigManager.java index 8bfe6f2d..877af294 100644 --- a/common/src/main/java/com/discordsrv/common/config/configurate/manager/abstraction/TranslatedConfigManager.java +++ b/common/src/main/java/com/discordsrv/common/config/configurate/manager/abstraction/TranslatedConfigManager.java @@ -32,6 +32,7 @@ import org.spongepowered.configurate.serialize.SerializationException; import org.spongepowered.configurate.yaml.YamlConfigurationLoader; import java.net.URL; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -39,10 +40,17 @@ import java.util.List; public abstract class TranslatedConfigManager> extends ConfigurateConfigManager { + private final DiscordSRV discordSRV; private String header; public TranslatedConfigManager(DiscordSRV discordSRV) { super(discordSRV); + this.discordSRV = discordSRV; + } + + protected TranslatedConfigManager(Path dataDirectory) { + super(dataDirectory); + this.discordSRV = null; } @Override @@ -100,6 +108,10 @@ public abstract class TranslatedConfigManager> CONFIGS = Arrays.asList( - new BukkitConfigManager(discordSRV), - new BukkitConnectionConfigManager(discordSRV) + new BukkitConfigManager(DATA_DIRECTORY), + new BukkitConnectionConfigManager(DATA_DIRECTORY) ); public static void main(String[] args) throws ConfigurateException { @@ -61,8 +63,7 @@ public final class DiscordSRVTranslation { try { Untranslated.Type type = data.value(); if (type.isValue()) { - Object value = destination.get(Object.class); - if (type.isComment()/* || !(value instanceof String)*/) { + if (type.isComment()) { destination.set(null); } else { destination.set(""); @@ -91,7 +92,7 @@ public final class DiscordSRVTranslation { .addProcessor(Untranslated.class, untranslatedProcessorFactory) .build(); - TranslationConfigManagerProxy configManagerProxy = new TranslationConfigManagerProxy<>(discordSRV, mapperFactory, configManager); + TranslationConfigManagerProxy configManagerProxy = new TranslationConfigManagerProxy<>(DATA_DIRECTORY, mapperFactory, configManager); CommentedConfigurationNode configurationNode = configManagerProxy.getDefaultNode(mapperFactory); convertCommentsToOptions(configurationNode, commentSection); diff --git a/i18n/src/main/java/com/discordsrv/config/MockDiscordSRV.java b/i18n/src/main/java/com/discordsrv/config/MockDiscordSRV.java deleted file mode 100644 index 8b653c61..00000000 --- a/i18n/src/main/java/com/discordsrv/config/MockDiscordSRV.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * This file is part of DiscordSRV, licensed under the GPLv3 License - * Copyright (c) 2016-2023 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.discordsrv.config; - -import com.discordsrv.common.AbstractDiscordSRV; -import com.discordsrv.common.bootstrap.IBootstrap; -import com.discordsrv.common.bootstrap.LifecycleManager; -import com.discordsrv.common.command.game.handler.ICommandHandler; -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.MainConfigManager; -import com.discordsrv.common.console.Console; -import com.discordsrv.common.debug.data.OnlineMode; -import com.discordsrv.common.logging.Logger; -import com.discordsrv.common.logging.backend.impl.JavaLoggerImpl; -import com.discordsrv.common.player.provider.AbstractPlayerProvider; -import com.discordsrv.common.plugin.PluginManager; -import com.discordsrv.common.scheduler.Scheduler; -import dev.vankka.dependencydownload.classpath.ClasspathAppender; -import org.jetbrains.annotations.NotNull; - -import java.nio.file.Path; -import java.nio.file.Paths; - -@SuppressWarnings("ConstantConditions") -public class MockDiscordSRV extends AbstractDiscordSRV { - - public MockDiscordSRV() { - super(new IBootstrap() { - @Override - public Logger logger() { - return JavaLoggerImpl.getRoot(); - } - - @Override - public ClasspathAppender classpathAppender() { - return null; - } - - @Override - public ClassLoader classLoader() { - return null; - } - - @Override - public LifecycleManager lifecycleManager() { - return null; - } - - @Override - public Path dataDirectory() { - return null; - } - }); - } - - @Override - public Path dataDirectory() { - return Paths.get(""); - } - - @Override - public Scheduler scheduler() { - return null; - } - - @Override - public Console console() { - return null; - } - - @Override - public PluginManager pluginManager() { - return null; - } - - @Override - public OnlineMode onlineMode() { - return null; - } - - @Override - public ICommandHandler commandHandler() { - return null; - } - - @Override - public @NotNull AbstractPlayerProvider playerProvider() { - return null; - } - - @Override - public ConnectionConfigManager connectionConfigManager() { - return null; - } - - @Override - public MainConfigManager configManager() { - return null; - } -} diff --git a/i18n/src/main/java/com/discordsrv/config/TranslationConfigManagerProxy.java b/i18n/src/main/java/com/discordsrv/config/TranslationConfigManagerProxy.java index 7cb7db13..c740238c 100644 --- a/i18n/src/main/java/com/discordsrv/config/TranslationConfigManagerProxy.java +++ b/i18n/src/main/java/com/discordsrv/config/TranslationConfigManagerProxy.java @@ -18,12 +18,13 @@ package com.discordsrv.config; -import com.discordsrv.common.DiscordSRV; -import com.discordsrv.common.config.configurate.manager.loader.YamlConfigLoaderProvider; import com.discordsrv.common.config.configurate.manager.abstraction.ConfigurateConfigManager; +import com.discordsrv.common.config.configurate.manager.loader.YamlConfigLoaderProvider; import org.spongepowered.configurate.objectmapping.ObjectMapper; import org.spongepowered.configurate.yaml.YamlConfigurationLoader; +import java.nio.file.Path; + public class TranslationConfigManagerProxy extends ConfigurateConfigManager implements YamlConfigLoaderProvider { @@ -31,8 +32,8 @@ public class TranslationConfigManagerProxy private final ObjectMapper.Factory objectMapper; private final ConfigurateConfigManager configManager; - public TranslationConfigManagerProxy(DiscordSRV discordSRV, ObjectMapper.Factory objectMapper, ConfigurateConfigManager configManager) { - super(discordSRV); + public TranslationConfigManagerProxy(Path dataDirectory, ObjectMapper.Factory objectMapper, ConfigurateConfigManager configManager) { + super(dataDirectory); this.objectMapper = objectMapper; this.configManager = configManager; }