Update configme (#1631)
* Upgrade to ConfigMe 1.0.1 * Use ConfigMe reader whenever possible, minor simplifications
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package fr.xephi.authme.settings.commandconfig;
|
||||
|
||||
import ch.jalu.configme.SettingsManager;
|
||||
import ch.jalu.configme.SettingsManagerBuilder;
|
||||
import fr.xephi.authme.initialization.DataFolder;
|
||||
import fr.xephi.authme.initialization.Reloadable;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
@@ -148,8 +149,11 @@ public class CommandManager implements Reloadable {
|
||||
File file = new File(dataFolder, "commands.yml");
|
||||
FileUtils.copyFileFromResource(file, "commands.yml");
|
||||
|
||||
SettingsManager settingsManager = new SettingsManager(
|
||||
YamlFileResourceProvider.loadFromFile(file), commandMigrationService, CommandSettingsHolder.class);
|
||||
SettingsManager settingsManager = SettingsManagerBuilder
|
||||
.withResource(YamlFileResourceProvider.loadFromFile(file))
|
||||
.configurationData(CommandSettingsHolder.class)
|
||||
.migrationService(commandMigrationService)
|
||||
.create();
|
||||
CommandConfig commandConfig = settingsManager.getProperty(CommandSettingsHolder.COMMANDS);
|
||||
onJoinCommands = newReplacer(commandConfig.getOnJoin());
|
||||
onLoginCommands = newOnLoginCmdReplacer(commandConfig.getOnLogin());
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package fr.xephi.authme.settings.commandconfig;
|
||||
|
||||
import ch.jalu.configme.configurationdata.ConfigurationData;
|
||||
import ch.jalu.configme.migration.MigrationService;
|
||||
import ch.jalu.configme.properties.Property;
|
||||
import ch.jalu.configme.resource.PropertyResource;
|
||||
import ch.jalu.configme.resource.PropertyReader;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import fr.xephi.authme.settings.SettingsMigrationService;
|
||||
@@ -30,10 +30,10 @@ class CommandMigrationService implements MigrationService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkAndMigrate(PropertyResource resource, List<Property<?>> properties) {
|
||||
final CommandConfig commandConfig = CommandSettingsHolder.COMMANDS.getValue(resource);
|
||||
if (moveOtherAccountsConfig(commandConfig) || isFileEmpty(resource)) {
|
||||
resource.setValue("", commandConfig);
|
||||
public boolean checkAndMigrate(PropertyReader reader, ConfigurationData configurationData) {
|
||||
final CommandConfig commandConfig = CommandSettingsHolder.COMMANDS.determineValue(reader);
|
||||
if (moveOtherAccountsConfig(commandConfig) || isAnyCommandMissing(reader)) {
|
||||
configurationData.setValue(CommandSettingsHolder.COMMANDS, commandConfig);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -59,7 +59,7 @@ class CommandMigrationService implements MigrationService {
|
||||
.replace("%playerip%", "%ip");
|
||||
}
|
||||
|
||||
private static boolean isFileEmpty(PropertyResource resource) {
|
||||
return COMMAND_CONFIG_PROPERTIES.stream().anyMatch(property -> resource.getObject(property) == null);
|
||||
private static boolean isAnyCommandMissing(PropertyReader reader) {
|
||||
return COMMAND_CONFIG_PROPERTIES.stream().anyMatch(property -> reader.getObject(property) == null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
package fr.xephi.authme.settings.commandconfig;
|
||||
|
||||
import ch.jalu.configme.SectionComments;
|
||||
import ch.jalu.configme.SettingsHolder;
|
||||
import ch.jalu.configme.configurationdata.CommentsConfiguration;
|
||||
import ch.jalu.configme.properties.BeanProperty;
|
||||
import ch.jalu.configme.properties.Property;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Settings holder class for the commands.yml settings.
|
||||
*/
|
||||
@@ -16,12 +13,11 @@ public final class CommandSettingsHolder implements SettingsHolder {
|
||||
public static final Property<CommandConfig> COMMANDS =
|
||||
new BeanProperty<>(CommandConfig.class, "", new CommandConfig());
|
||||
|
||||
|
||||
private CommandSettingsHolder() {
|
||||
}
|
||||
|
||||
@SectionComments
|
||||
public static Map<String, String[]> sectionComments() {
|
||||
@Override
|
||||
public void registerComments(CommentsConfiguration conf) {
|
||||
String[] rootComments = {
|
||||
"This configuration file allows you to execute commands on various events.",
|
||||
"Supported placeholders in commands:",
|
||||
@@ -60,21 +56,15 @@ public final class CommandSettingsHolder implements SettingsHolder {
|
||||
" ifNumberOfAccountsAtLeast: 5"
|
||||
};
|
||||
|
||||
Map<String, String[]> commentMap = new HashMap<>();
|
||||
commentMap.put("", rootComments);
|
||||
commentMap.put("onFirstLogin", new String[]{
|
||||
"Commands to run for players logging in whose 'last login date' was empty"
|
||||
});
|
||||
commentMap.put("onUnregister", new String[]{
|
||||
"Commands to run whenever a player is unregistered (by himself, or by an admin)"
|
||||
});
|
||||
commentMap.put("onLogout", new String[]{
|
||||
conf.setComment("", rootComments);
|
||||
conf.setComment("onFirstLogin",
|
||||
"Commands to run for players logging in whose 'last login date' was empty");
|
||||
conf.setComment("onUnregister",
|
||||
"Commands to run whenever a player is unregistered (by himself, or by an admin)");
|
||||
conf.setComment("onLogout",
|
||||
"These commands are called whenever a logged in player uses /logout or quits.",
|
||||
"The commands are not run if a player that was not logged in quits the server.",
|
||||
"Note: if your server crashes, these commands won't be run, so don't rely on them to undo",
|
||||
"'onLogin' commands that would be dangerous for non-logged in players to have!"
|
||||
});
|
||||
return commentMap;
|
||||
"'onLogin' commands that would be dangerous for non-logged in players to have!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user