Update Config and Language class to fully use the new base

This commit is contained in:
GeorgH93 2022-02-26 19:27:52 +01:00
parent a97ba36ebc
commit 53e99e1aef
No known key found for this signature in database
GPG Key ID: D1630D37F9E4B3C8
2 changed files with 33 additions and 27 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 GeorgH93
* Copyright (C) 2022 GeorgH93
*
* 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
@ -17,34 +17,34 @@
package at.pcgamingfreaks.Minepacks.Bukkit.Database;
import at.pcgamingfreaks.Bukkit.Configuration;
import at.pcgamingfreaks.Bukkit.MCVersion;
import at.pcgamingfreaks.Bukkit.MinecraftMaterial;
import at.pcgamingfreaks.Bukkit.Util.Utils;
import at.pcgamingfreaks.Config.Configuration;
import at.pcgamingfreaks.Config.ILanguageConfiguration;
import at.pcgamingfreaks.Config.YamlFileManager;
import at.pcgamingfreaks.ConsoleColor;
import at.pcgamingfreaks.Database.DatabaseConnectionConfiguration;
import at.pcgamingfreaks.Minepacks.Bukkit.API.WorldBlacklistMode;
import at.pcgamingfreaks.Minepacks.Bukkit.Database.Helper.OldFileUpdater;
import at.pcgamingfreaks.Minepacks.Bukkit.MagicValues;
import at.pcgamingfreaks.Minepacks.Bukkit.Minepacks;
import at.pcgamingfreaks.Minepacks.Bukkit.ShrinkApproach;
import at.pcgamingfreaks.YamlFileManager;
import at.pcgamingfreaks.Version;
import org.bukkit.*;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import java.io.FileNotFoundException;
import java.util.*;
public class Config extends Configuration implements DatabaseConnectionConfiguration
public class Config extends Configuration implements DatabaseConnectionConfiguration, ILanguageConfiguration
{
private static final int CONFIG_VERSION = 32, UPGRADE_THRESHOLD = CONFIG_VERSION, PRE_V2_VERSION = 20;
private static final Version CONFIG_VERSION = new Version(32), PRE_V2_VERSION = new Version(20);
public Config(JavaPlugin plugin)
public Config(Minepacks plugin)
{
super(plugin, CONFIG_VERSION, UPGRADE_THRESHOLD);
languageKey = "Language.Language";
languageUpdateKey = "Language.UpdateMode";
super(plugin, CONFIG_VERSION);
}
@Override
@ -56,16 +56,16 @@ protected void doUpdate()
@Override
protected void doUpgrade(@NotNull YamlFileManager oldConfig)
{
if(oldConfig.getVersion() < PRE_V2_VERSION) // Pre V2.0 config file
if(oldConfig.getVersion().olderThan(PRE_V2_VERSION)) // Pre V2.0 config file
{
OldFileUpdater.updateConfig(oldConfig.getYamlE(), getConfigE());
}
else
{
Map<String, String> remappedKeys = new HashMap<>();
if(oldConfig.getVersion() <= 23) remappedKeys.put("ItemFilter.Materials", "ItemFilter.Blacklist");
if(oldConfig.getVersion() <= 28) remappedKeys.put("Misc.AutoUpdate.Enabled", "Misc.AutoUpdate");
if(oldConfig.getVersion() <= 30)
if(oldConfig.getVersion().olderOrEqualThan(new Version(23))) remappedKeys.put("ItemFilter.Materials", "ItemFilter.Blacklist");
if(oldConfig.getVersion().olderOrEqualThan(new Version(28))) remappedKeys.put("Misc.AutoUpdate.Enabled", "Misc.AutoUpdate");
if(oldConfig.getVersion().olderOrEqualThan(new Version(30)))
{
remappedKeys.put("WorldSettings.FilteredWorlds", "WorldSettings.Blacklist");
remappedKeys.put("WorldSettings.BockMode", "WorldSettings.BlacklistMode");
@ -130,7 +130,7 @@ public boolean useOnlineUUIDs()
{
logger.warning("When using BungeeCord please make sure to set the UUID_Type config option explicitly!");
}
return plugin.getServer().getOnlineMode();
return Bukkit.getServer().getOnlineMode();
}
return type.equals("online");
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 GeorgH93
* Copyright (C) 2022 GeorgH93
*
* 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
@ -17,34 +17,32 @@
package at.pcgamingfreaks.Minepacks.Bukkit.Database;
import at.pcgamingfreaks.Bukkit.Message.Message;
import at.pcgamingfreaks.Config.YamlFileManager;
import at.pcgamingfreaks.Minepacks.Bukkit.Database.Helper.OldFileUpdater;
import at.pcgamingfreaks.Minepacks.Bukkit.Minepacks;
import at.pcgamingfreaks.Version;
import at.pcgamingfreaks.YamlFileManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
public class Language extends at.pcgamingfreaks.Bukkit.Language
public class Language extends at.pcgamingfreaks.Bukkit.Config.Language
{
private static final Version LANG_VERSION = new Version(19), UPGRADE_THRESHOLD = LANG_VERSION;
private static final Version LANG_VERSION = new Version(19);
public Language(JavaPlugin plugin)
public Language(Minepacks plugin)
{
super(plugin, LANG_VERSION, UPGRADE_THRESHOLD);
super(plugin, LANG_VERSION);
}
@Override
protected void doUpdate() {}
@Override
protected void doUpgrade(@NotNull YamlFileManager oldLang)
{
if(oldLang.getVersion() < 10) // Pre v2.0 versions
if(oldLang.getVersion().olderThan(new Version(10))) // Pre v2.0 versions
{
OldFileUpdater.updateLanguage(oldLang.getYamlE(), getYaml(), plugin.getLogger());
OldFileUpdater.updateLanguage(oldLang.getYamlE(), getYaml(), getLogger());
}
else
{
@ -62,4 +60,12 @@ public String[] getCommandAliases(final String command, final @NotNull String...
List<String> aliases = getLangE().getStringList("Command." + command, new ArrayList<>(0));
return (aliases.size() > 0) ? aliases.toArray(new String[0]) : defaults;
}
@Override
public @NotNull Message getMessage(@NotNull String path)
{
Message msg = super.getMessage(path);
msg.enableStringFormat(); // TODO use new placeholder system instead!
return msg;
}
}