#761 Add group options as Property objects and #449 remove legacy Settings class

This commit is contained in:
ljacqu 2016-07-23 15:34:48 +02:00
parent 18a9fbaa26
commit bcc31afb90
12 changed files with 29 additions and 83 deletions

View File

@ -35,7 +35,6 @@ import fr.xephi.authme.permission.PermissionsSystemType;
import fr.xephi.authme.process.Management;
import fr.xephi.authme.security.crypts.SHA256;
import fr.xephi.authme.settings.NewSetting;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.SettingsMigrationService;
import fr.xephi.authme.settings.SpawnLoader;
import fr.xephi.authme.settings.properties.DatabaseSettings;
@ -205,13 +204,6 @@ public class AuthMe extends JavaPlugin {
// Apply settings to the logger
ConsoleLogger.setLoggingOptions(newSettings);
// Old settings manager
if (!loadSettings()) {
getServer().shutdown();
setEnabled(false);
return;
}
// Connect to the database and setup tables
try {
setupDatabase(newSettings);
@ -373,22 +365,10 @@ public class AuthMe extends JavaPlugin {
}
/**
* Load the plugin's settings.
* Loads the plugin's settings.
*
* @return True on success, false on failure.
* @return The settings instance, or null if it could not be constructed
*/
private boolean loadSettings() {
try {
new Settings(this);
return true;
} catch (Exception e) {
ConsoleLogger.logException("Can't load the configuration file... Something went wrong. "
+ "To avoid security issues the server will shut down!", e);
getServer().shutdown();
}
return false;
}
private NewSetting createNewSetting() {
File configFile = new File(getDataFolder(), "config.yml");
PropertyMap properties = SettingsFieldRetriever.getAllPropertyFields();

View File

@ -5,7 +5,7 @@ import fr.xephi.authme.cache.limbo.LimboCache;
import fr.xephi.authme.cache.limbo.PlayerData;
import fr.xephi.authme.initialization.Reloadable;
import fr.xephi.authme.settings.NewSetting;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.HooksSettings;
import fr.xephi.authme.settings.properties.PluginSettings;
import fr.xephi.authme.settings.properties.SecuritySettings;
import org.bukkit.entity.Player;
@ -116,8 +116,8 @@ public class AuthGroupHandler implements Reloadable {
@Override
public void reload() {
unloggedInGroup = settings.getProperty(SecuritySettings.UNLOGGEDIN_GROUP);
unregisteredGroup = Settings.unRegisteredGroup;
registeredGroup = Settings.getRegisteredGroup;
unregisteredGroup = settings.getProperty(HooksSettings.UNREGISTERED_GROUP);
registeredGroup = settings.getProperty(HooksSettings.REGISTERED_GROUP);
}
}

View File

@ -5,7 +5,7 @@ import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.permission.AuthGroupType;
import fr.xephi.authme.process.ProcessService;
import fr.xephi.authme.process.SynchronousProcess;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.HooksSettings;
import fr.xephi.authme.task.PlayerDataTaskManager;
import fr.xephi.authme.util.Utils;
import org.bukkit.entity.Player;
@ -26,7 +26,7 @@ public class ProcessSyncEmailRegister implements SynchronousProcess {
public void processEmailRegister(Player player) {
final String name = player.getName().toLowerCase();
if (!Settings.getRegisteredGroup.isEmpty()) {
if (!service.getProperty(HooksSettings.REGISTERED_GROUP).isEmpty()) {
service.setGroup(player, AuthGroupType.REGISTERED);
}
service.send(player, MessageKey.ACCOUNT_NOT_ACTIVATED);

View File

@ -7,8 +7,8 @@ import fr.xephi.authme.permission.AuthGroupType;
import fr.xephi.authme.process.ProcessService;
import fr.xephi.authme.process.SynchronousProcess;
import fr.xephi.authme.service.BungeeService;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.EmailSettings;
import fr.xephi.authme.settings.properties.HooksSettings;
import fr.xephi.authme.settings.properties.RegistrationSettings;
import fr.xephi.authme.task.PlayerDataTaskManager;
import fr.xephi.authme.util.Utils;
@ -63,7 +63,7 @@ public class ProcessSyncPasswordRegister implements SynchronousProcess {
}
public void processPasswordRegister(Player player) {
if (!Settings.getRegisteredGroup.isEmpty()) {
if (!service.getProperty(HooksSettings.REGISTERED_GROUP).isEmpty()) {
service.setGroup(player, AuthGroupType.REGISTERED);
}

View File

@ -10,13 +10,12 @@ import fr.xephi.authme.permission.AuthGroupType;
import fr.xephi.authme.process.AsynchronousProcess;
import fr.xephi.authme.process.ProcessService;
import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.HooksSettings;
import fr.xephi.authme.settings.properties.RegistrationSettings;
import fr.xephi.authme.settings.properties.RestrictionSettings;
import fr.xephi.authme.task.PlayerDataTaskManager;
import fr.xephi.authme.util.BukkitService;
import fr.xephi.authme.util.TeleportationService;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
@ -67,7 +66,7 @@ public class AsynchronousUnregister implements AsynchronousProcess {
teleportationService.teleportOnJoin(player);
player.saveData();
playerCache.removePlayer(player.getName().toLowerCase());
if (!Settings.getRegisteredGroup.isEmpty()) {
if (!service.getProperty(HooksSettings.REGISTERED_GROUP).isEmpty()) {
service.setGroup(player, AuthGroupType.UNREGISTERED);
}
limboCache.deletePlayerData(player);
@ -79,7 +78,7 @@ public class AsynchronousUnregister implements AsynchronousProcess {
ConsoleLogger.info(player.getName() + " unregistered himself");
return; // TODO ljacqu 20160612: Why return here? No blind effect? Player not removed from PlayerCache?
}
if (!Settings.unRegisteredGroup.isEmpty()) {
if (!service.getProperty(HooksSettings.UNREGISTERED_GROUP).isEmpty()) {
service.setGroup(player, AuthGroupType.UNREGISTERED);
}
playerCache.removePlayer(name);

View File

@ -1,25 +0,0 @@
package fr.xephi.authme.settings;
import fr.xephi.authme.AuthMe;
import org.bukkit.configuration.file.FileConfiguration;
/**
* Old settings manager. See {@link NewSetting} for the new manager.
*/
@Deprecated
public final class Settings {
public static String unRegisteredGroup;
public static String getRegisteredGroup;
/**
* Constructor for Settings.
*
* @param pl AuthMe
*/
public Settings(AuthMe pl) {
FileConfiguration configFile = pl.getConfig();
unRegisteredGroup = configFile.getString("GroupOptions.UnregisteredPlayerGroup", "");
getRegisteredGroup = configFile.getString("GroupOptions.RegisteredPlayerGroup", "");
}
}

View File

@ -67,7 +67,8 @@ public class SettingsMigrationService {
String[] deprecatedProperties = {
"Converter.Rakamak.newPasswordHash", "Hooks.chestshop", "Hooks.legacyChestshop", "Hooks.notifications",
"Passpartu", "Performances", "settings.restrictions.enablePasswordVerifier", "Xenoforo.predefinedSalt",
"VeryGames", "settings.restrictions.allowAllCommandsIfRegistrationIsOptional"};
"VeryGames", "settings.restrictions.allowAllCommandsIfRegistrationIsOptional", "DataSource.mySQLWebsite",
"Hooks.customAttributes", "Security.stop.kickPlayersBeforeStopping"};
for (String deprecatedPath : deprecatedProperties) {
if (configuration.contains(deprecatedPath)) {
return true;

View File

@ -50,7 +50,7 @@ public class DatabaseSettings implements SettingsClass {
public static final Property<String> MYSQL_COL_NAME =
newProperty("DataSource.mySQLColumnName", "username");
@Comment("Column for storing or checking players RealName ")
@Comment("Column for storing or checking players RealName")
public static final Property<String> MYSQL_COL_REALNAME =
newProperty("DataSource.mySQLRealName", "realname");
@ -98,10 +98,6 @@ public class DatabaseSettings implements SettingsClass {
public static final Property<String> MYSQL_COL_GROUP =
newProperty("ExternalBoardOptions.mySQLColumnGroup", "");
@Comment("Enable this when you allow registration through a website")
public static final Property<Boolean> MYSQL_WEBSITE =
newProperty("DataSource.mySQLWebsite", false);
private DatabaseSettings() {
}

View File

@ -31,10 +31,6 @@ public class HooksSettings implements SettingsClass {
public static final Property<Boolean> USE_ESSENTIALS_MOTD =
newProperty("Hooks.useEssentialsMotd", false);
@Comment("Do we need to cache custom Attributes?")
public static final Property<Boolean> CACHE_CUSTOM_ATTRIBUTES =
newProperty("Hooks.customAttributes", false);
@Comment({
"-1 means disabled. If you want that only activated players",
"can log into your server, you can set here the group number",
@ -62,6 +58,14 @@ public class HooksSettings implements SettingsClass {
public static final Property<String> WORDPRESS_TABLE_PREFIX =
newProperty("ExternalBoardOptions.wordpressTablePrefix", "wp_");
@Comment("Unregistered permission group")
public static final Property<String> UNREGISTERED_GROUP =
newProperty("GroupOptions.UnregisteredPlayerGroup", "");
@Comment("Registered permission group")
public static final Property<String> REGISTERED_GROUP =
newProperty("GroupOptions.RegisteredPlayerGroup", "");
private HooksSettings() {
}

View File

@ -42,11 +42,6 @@ public class SecuritySettings implements SettingsClass {
public static final Property<Integer> CAPTCHA_LENGTH =
newProperty("Security.captcha.captchaLength", 5);
@Comment({"Kick players before stopping the server, that allow us to save position of players",
"and all needed information correctly without any corruption."})
public static final Property<Boolean> KICK_PLAYERS_BEFORE_STOPPING =
newProperty("Security.stop.kickPlayersBeforeStopping", true);
@Comment("Minimum length of password")
public static final Property<Integer> MIN_PASSWORD_LENGTH =
newProperty("settings.security.minPasswordLength", 5);

View File

@ -4,7 +4,6 @@ import fr.xephi.authme.settings.domain.Comment;
import fr.xephi.authme.settings.domain.Property;
import fr.xephi.authme.settings.domain.SettingsClass;
import fr.xephi.authme.settings.propertymap.PropertyMap;
import fr.xephi.authme.util.StringUtils;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
@ -67,7 +66,7 @@ public final class SettingsFieldRetriever {
return (Property<?>) field.get(null);
} catch (IllegalAccessException e) {
throw new IllegalStateException("Could not fetch field '" + field.getName() + "' from class '"
+ field.getDeclaringClass().getSimpleName() + "': " + StringUtils.formatException(e));
+ field.getDeclaringClass().getSimpleName() + "'", e);
}
}
return null;

View File

@ -40,8 +40,6 @@ DataSource:
mySQLlastlocWorld: world
# Column for RealName
mySQLRealName: realname
# Enable this when you allow registration through a website
mySQLWebsite: false
settings:
# The name shown in the help messages.
helpHeader: AuthMeReloaded
@ -326,10 +324,6 @@ Security:
maxLoginTry: 5
# Captcha length
captchaLength: 5
stop:
# Kick players before stopping the server, that allow us to save position of players, and all needed
# information correctly without any corruption.
kickPlayersBeforeStopping: true
tempban:
# Tempban a user's IP address if they enter the wrong password too many times
enableTempban: false
@ -390,8 +384,6 @@ Hooks:
disableSocialSpy: true
# Do we need to force /motd Essentials command on join?
useEssentialsMotd: false
# Do we need to cache custom Attributes?
customAttributes: false
Purge:
# If enabled, AuthMe automatically purges old, unused accounts
useAutoPurge: false
@ -429,3 +421,8 @@ Protection:
antiBotSensibility: 10
# Duration in minutes of the antibot automatic system
antiBotDuration: 10
GroupOptions:
# Registered permission group
RegisteredPlayerGroup: ''
# Unregistered permission group
UnregisteredPlayerGroup: ''