Merge branch 'master' of https://github.com/AuthMe-Team/AuthMeReloaded into 411-forced-commands
This commit is contained in:
@@ -1,35 +1,38 @@
|
||||
package fr.xephi.authme.settings;
|
||||
|
||||
import com.github.authme.configme.properties.Property;
|
||||
import com.github.authme.configme.resource.PropertyResource;
|
||||
import com.github.authme.configme.SettingsManager;
|
||||
import com.github.authme.configme.properties.StringListProperty;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Property whose value is a set of entries of a given enum.
|
||||
*/
|
||||
// TODO https://github.com/AuthMe/ConfigMe/issues/27: Should be a Property of Set<E> type
|
||||
public class EnumSetProperty<E extends Enum<E>> extends Property<List<E>> {
|
||||
// TODO #1014: This property type currently extends StringListProperty with a dedicated method to convert the values
|
||||
// into a Set of the selected enum due to multiple issues on ConfigMe's side.
|
||||
public class EnumSetProperty<E extends Enum<E>> extends StringListProperty {
|
||||
|
||||
private final Class<E> enumClass;
|
||||
|
||||
public EnumSetProperty(Class<E> enumClass, String path, List<E> defaultValue) {
|
||||
super(path, defaultValue);
|
||||
public EnumSetProperty(Class<E> enumClass, String path, String... values) {
|
||||
super(path, values);
|
||||
this.enumClass = enumClass;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<E> getFromResource(PropertyResource resource) {
|
||||
List<?> elements = resource.getList(getPath());
|
||||
if (elements != null) {
|
||||
return elements.stream()
|
||||
.map(val -> toEnum(String.valueOf(val)))
|
||||
.filter(e -> e != null)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
return null;
|
||||
/**
|
||||
* Returns the value as a set of enum entries.
|
||||
*
|
||||
* @param settings the settings manager to look up the raw value with
|
||||
* @return the property's value as mapped enum entries
|
||||
*/
|
||||
public Set<E> asEnumSet(SettingsManager settings) {
|
||||
List<String> entries = settings.getProperty(this);
|
||||
return entries.stream()
|
||||
.map(str -> toEnum(str))
|
||||
.filter(e -> e != null)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
private E toEnum(String str) {
|
||||
|
||||
@@ -48,10 +48,10 @@ public class SpawnLoader implements Reloadable {
|
||||
@Inject
|
||||
SpawnLoader(@DataFolder File pluginFolder, Settings settings, PluginHookService pluginHookService,
|
||||
DataSource dataSource) {
|
||||
File spawnFile = new File(pluginFolder, "spawn.yml");
|
||||
// TODO ljacqu 20160312: Check if resource could be copied and handle the case if not
|
||||
File spawnFile = new File(pluginFolder, "spawn.yml");
|
||||
FileUtils.copyFileFromResource(spawnFile, "spawn.yml");
|
||||
this.authMeConfigurationFile = new File(pluginFolder, "spawn.yml");
|
||||
this.authMeConfigurationFile = spawnFile;
|
||||
this.settings = settings;
|
||||
this.pluginHookService = pluginHookService;
|
||||
reload();
|
||||
|
||||
@@ -6,7 +6,6 @@ import com.github.authme.configme.properties.Property;
|
||||
import fr.xephi.authme.security.HashAlgorithm;
|
||||
import fr.xephi.authme.settings.EnumSetProperty;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.github.authme.configme.properties.PropertyInitializer.newLowercaseListProperty;
|
||||
@@ -83,8 +82,8 @@ public class SecuritySettings implements SettingsHolder {
|
||||
"legacyHashes:",
|
||||
"- 'SHA1'"
|
||||
})
|
||||
public static final Property<List<HashAlgorithm>> LEGACY_HASHES =
|
||||
new EnumSetProperty<>(HashAlgorithm.class, "settings.security.legacyHashes", Collections.emptyList());
|
||||
public static final Property<List<String>> LEGACY_HASHES =
|
||||
new EnumSetProperty<>(HashAlgorithm.class, "settings.security.legacyHashes");
|
||||
|
||||
@Comment({"Prevent unsafe passwords from being used; put them in lowercase!",
|
||||
"You should always set 'help' as unsafePassword due to possible conflicts.",
|
||||
|
||||
Reference in New Issue
Block a user