Minor tweaks to GenericConfig & ContextProvider

# Changes:
- Changed Configuration#getList(String, Class) to Configuration#getCollection(String, Class)

- Renamed GenericConfiguration -> GenericConfig

- Implemented semantics for GenericConfig#getCollection and GenericConfig#getStringList

- Adjusted return value of ContextProvider#fromString to return Optional<T> instead of @Nullable T

- Adjusted classes which used previous API methods to use the newly updated ones.
This commit is contained in:
Paul Reilly
2023-08-30 20:49:22 -05:00
parent 26f4e0746b
commit 4681fc9596
7 changed files with 172 additions and 83 deletions

View File

@ -28,6 +28,7 @@ import fns.veritas.bukkit.BukkitNative;
import fns.veritas.bukkit.ServerListener;
import fns.veritas.client.BotClient;
import fns.veritas.client.BotConfig;
import java.io.IOException;
import org.bukkit.Bukkit;
public class Aggregate
@ -40,13 +41,30 @@ public class Aggregate
public Aggregate(final Veritas plugin)
{
BotClient bot1;
this.plugin = plugin;
this.bot = new BotClient(new BotConfig(plugin));
try
{
bot1 = new BotClient(new BotConfig(plugin));
}
catch (IOException ex)
{
getLogger().error("Failed to load bot config! Shutting down...");
getLogger().error(ex);
this.bot = null;
this.serverListener = null;
this.bukkitNativeListener = null;
Bukkit.getPluginManager().disablePlugin(plugin);
return;
}
this.bukkitNativeListener = new BukkitNative(plugin);
this.serverListener = new ServerListener(plugin);
Bukkit.getServer().getPluginManager().registerEvents(this.getBukkitNativeListener(), plugin);
this.getServerListener().minecraftChatBound().subscribe();
this.bot = bot1;
}
public static FNS4J getLogger()

View File

@ -24,7 +24,8 @@
package fns.veritas.client;
import discord4j.common.util.Snowflake;
import fns.patchwork.config.WrappedBukkitConfiguration;
import fns.patchwork.config.ConfigType;
import fns.patchwork.config.GenericConfig;
import fns.veritas.Aggregate;
import fns.veritas.Veritas;
import java.io.File;
@ -41,12 +42,11 @@ public class BotConfig
public static final String GUILD_ID = "guild_id";
@NonNls
private static final String BOT_TOKEN = "bot_token";
private final WrappedBukkitConfiguration config;
private final GenericConfig config;
public BotConfig(final Veritas plugin)
public BotConfig(final Veritas plugin) throws IOException
{
this.config = new WrappedBukkitConfiguration(f0(plugin),
new File(plugin.getDataFolder(), "config.yml"));
this.config = new GenericConfig(ConfigType.TOML, plugin, "config.toml");
}
public String getToken()