Add configme

This commit is contained in:
Ryder Belserion 2023-02-28 01:26:55 -05:00
parent a28521f105
commit cf4cab91be
No known key found for this signature in database
GPG Key ID: 8FC2E6C54BBF05FE
3 changed files with 124 additions and 0 deletions

View File

@ -0,0 +1,61 @@
package us.crazycrew.crazyauctions.configs;
import ch.jalu.configme.Comment;
import ch.jalu.configme.SettingsHolder;
import ch.jalu.configme.configurationdata.CommentsConfiguration;
import ch.jalu.configme.properties.Property;
import static ch.jalu.configme.properties.PropertyInitializer.newProperty;
public class PluginSettings implements SettingsHolder {
// Empty constructor required by SettingsHolder
public PluginSettings() {}
@Override
public void registerComments(CommentsConfiguration conf) {
String[] header = {
"Support: https://discord.gg/crazycrew",
"Github: https://github.com/Crazy-Crew",
"",
"Issues: https://github.com/Crazy-Crew/CrazyCrates/issues",
"Features: https://github.com/Crazy-Crew/CrazyCrates/discussions"
};
conf.setComment("settings", header);
}
@Comment("The command prefix that is shown at the beginning of every message.")
public static final Property<String> COMMAND_PREFIX = newProperty("settings.prefix.command", "<red>[</red><green>CrazyAuctions</green><red>]</green> ");
@Comment("The prefix that is shown for messages sent in console such as logging messages.")
public static final Property<String> CONSOLE_PREFIX = newProperty("settings.prefix.console", "<gradient:#fe5f55:#6b55b5>[CrazyAuctions]</gradient> ");
@Comment({
"Choose the language you prefer to use on your server!",
"",
"Currently Available:",
" > en-US ( English )",
"",
"If you do not see your language above, You can contribute by modifying the current en-US.yml",
"https://github.com/Crazy-Crew/CrazyAuctions/blob/main/platforms/paper/src/main/resources/locale/en-US.yml",
"Submit your finalized config using https://bin.bloom.host/ and send it to us in https://discord.gg/crazycrew",
""
})
public static final Property<String> LOCALE_FILE = newProperty("settings.locale-file", "en-US");
@Comment("Whether you want to have verbose logging enabled or not.")
public static final Property<Boolean> VERBOSE_LOGGING = newProperty("settings.verbose-logging", true);
@Comment("Whether or not you would like to check for plugin updates on startup.")
public static final Property<Boolean> UPDATE_CHECKER = newProperty("settings.update-checker", true);
@Comment("Whether or not you would like to allow us to collect statistics on how our plugin is used.")
public static final Property<Boolean> PLUGIN_METRICS = newProperty("settings.toggle-metrics", true);
@Comment({
"What command aliases do you want to use?",
"You can use as many as you would like, Separate each command using : and do not use any spaces!"
})
public static final Property<String> PLUGIN_ALIASES = newProperty("settings.plugin-aliases", "crazyauctions:ca");
}

View File

@ -27,6 +27,9 @@ crazycore = { module = "us.crazycrew.crazycore:crazycore-core", version.ref = "c
triumph_cmds = { module = "dev.triumphteam:triumph-cmd-bukkit", version = "2.0.0-SNAPSHOT" }
triumph_gui = { module = "dev.triumphteam:triumph-gui", version = "3.1.2" }
# Config
config_me = { module = "ch.jalu:configme", version = "1.3.0" }
# Misc
bstats_bukkit = { module = "org.bstats:bstats-bukkit", version = "3.0.0" }
vault_api = { module = "com.github.MilkBowl:VaultAPI", version = "1.7" }

View File

@ -0,0 +1,60 @@
package us.crazycrew.crazyauctions.configs.migrations;
import ch.jalu.configme.configurationdata.ConfigurationData;
import ch.jalu.configme.migration.PlainMigrationService;
import ch.jalu.configme.resource.PropertyReader;
import org.bukkit.configuration.file.YamlConfiguration;
import us.crazycrew.crazycore.CrazyCore;
import us.crazycrew.crazycore.CrazyLogger;
import java.nio.file.Path;
public class PluginMigrationService extends PlainMigrationService {
@Override
protected boolean performMigrations(PropertyReader reader, ConfigurationData configurationData) {
return convert(reader, "example.test", "config.yml", true)
| convert(reader, "", "", true);
}
private boolean convert(PropertyReader reader, String oldValue, String newFile, boolean cascade) {
if (reader.contains(oldValue)) {
Path nFile = CrazyCore.api().getDirectory().resolve(newFile);
YamlConfiguration yamlNewFile = YamlConfiguration.loadConfiguration(nFile.toFile());
CrazyLogger.info("Starting the config migration process...");
CrazyLogger.info("Found old config value (" + oldValue + ")");
if (!nFile.toFile().exists()) {
try {
//noinspection ResultOfMethodCallIgnored
nFile.toFile().createNewFile();
} catch (Exception exception) {
exception.printStackTrace();
}
}
for (String child : reader.getChildKeys(oldValue)) {
if (cascade) {
for (String doubleChild : reader.getChildKeys(child)) {
yamlNewFile.set(doubleChild, reader.getObject(doubleChild));
}
} else {
yamlNewFile.set(child, reader.getObject(child));
}
}
try {
yamlNewFile.save(nFile.toFile());
CrazyLogger.info("The migration process is complete!");
} catch (Exception exception) {
exception.printStackTrace();
}
return true;
}
return false;
}
}