Move some configuations from PluginSettings to CommonSettings (new created)
This commit is contained in:
parent
d22ec8c34a
commit
ea98f7b9f2
@ -11,6 +11,7 @@ import fr.xephi.authme.logger.ConsoleLoggerFactory;
|
||||
import fr.xephi.authme.logger.Log4JFilter;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.CommonSettings;
|
||||
import fr.xephi.authme.settings.properties.DatabaseSettings;
|
||||
import fr.xephi.authme.settings.properties.EmailSettings;
|
||||
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||
@ -56,7 +57,7 @@ public class OnStartupTasks {
|
||||
final Metrics metrics = new Metrics(plugin, 18479);
|
||||
|
||||
metrics.addCustomChart(new SimplePie("messages_language",
|
||||
() -> settings.getProperty(PluginSettings.MESSAGES_LANGUAGE)));
|
||||
() -> settings.getProperty(CommonSettings.MESSAGES_LANGUAGE)));
|
||||
metrics.addCustomChart(new SimplePie("database_backend",
|
||||
() -> settings.getProperty(DatabaseSettings.BACKEND).toString()));
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@ import fr.xephi.authme.initialization.DataFolder;
|
||||
import fr.xephi.authme.initialization.Reloadable;
|
||||
import fr.xephi.authme.logger.ConsoleLoggerFactory;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.CommonSettings;
|
||||
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||
import fr.xephi.authme.util.FileUtils;
|
||||
import fr.xephi.authme.util.message.I18NUtils;
|
||||
@ -45,7 +46,7 @@ public abstract class AbstractMessageFileHandler implements Reloadable {
|
||||
@Override
|
||||
@PostConstruct
|
||||
public void reload() {
|
||||
String language = settings.getProperty(PluginSettings.MESSAGES_LANGUAGE);
|
||||
String language = getLanguage();
|
||||
filename = createFilePath(language);
|
||||
File messagesFile = initializeFile(filename);
|
||||
configuration = Configuration.loadFromFile(messagesFile);
|
||||
@ -53,7 +54,7 @@ public abstract class AbstractMessageFileHandler implements Reloadable {
|
||||
}
|
||||
|
||||
protected String getLanguage() {
|
||||
return settings.getProperty(PluginSettings.MESSAGES_LANGUAGE);
|
||||
return settings.getProperty(CommonSettings.MESSAGES_LANGUAGE);
|
||||
}
|
||||
|
||||
protected File getUserLanguageFile() {
|
||||
|
||||
@ -28,6 +28,7 @@ import fr.xephi.authme.service.bungeecord.BungeeSender;
|
||||
import fr.xephi.authme.service.bungeecord.MessageType;
|
||||
import fr.xephi.authme.service.velocity.VelocitySender;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.CommonSettings;
|
||||
import fr.xephi.authme.settings.properties.DatabaseSettings;
|
||||
import fr.xephi.authme.settings.properties.EmailSettings;
|
||||
import fr.xephi.authme.settings.properties.HooksSettings;
|
||||
@ -193,7 +194,7 @@ public class AsynchronousLogin implements AsynchronousProcess {
|
||||
return null;
|
||||
}
|
||||
|
||||
boolean isAsync = service.getProperty(PluginSettings.USE_ASYNC_TASKS);
|
||||
boolean isAsync = service.getProperty(CommonSettings.USE_ASYNC_TASKS);
|
||||
AuthMeAsyncPreLoginEvent event = new AuthMeAsyncPreLoginEvent(player, isAsync);
|
||||
bukkitService.callEvent(event);
|
||||
if (!event.canLogin()) {
|
||||
|
||||
@ -11,6 +11,7 @@ import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.service.SessionService;
|
||||
import fr.xephi.authme.service.ValidationService;
|
||||
import fr.xephi.authme.settings.SpawnLoader;
|
||||
import fr.xephi.authme.settings.properties.CommonSettings;
|
||||
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||
import fr.xephi.authme.util.PlayerUtils;
|
||||
import org.bukkit.Location;
|
||||
@ -97,7 +98,7 @@ public class AsynchronousQuit implements AsynchronousProcess {
|
||||
//always update the database when the player quit the game (if sessions are disabled)
|
||||
if (wasLoggedIn) {
|
||||
database.setUnlogged(name);
|
||||
if (!service.getProperty(PluginSettings.SESSIONS_ENABLED)) {
|
||||
if (!service.getProperty(CommonSettings.SESSIONS_ENABLED)) {
|
||||
sessionService.revokeSession(name);
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,7 +8,7 @@ import fr.xephi.authme.security.crypts.HashedPassword;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.service.ValidationService;
|
||||
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||
import fr.xephi.authme.settings.properties.CommonSettings;
|
||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -21,7 +21,7 @@ import javax.inject.Inject;
|
||||
* @param <P> the parameters type
|
||||
*/
|
||||
abstract class AbstractPasswordRegisterExecutor<P extends AbstractPasswordRegisterParams>
|
||||
implements RegistrationExecutor<P> {
|
||||
implements RegistrationExecutor<P> {
|
||||
|
||||
/**
|
||||
* Number of ticks to wait before running the login action when it is run synchronously.
|
||||
@ -51,7 +51,7 @@ abstract class AbstractPasswordRegisterExecutor<P extends AbstractPasswordRegist
|
||||
@Override
|
||||
public boolean isRegistrationAdmitted(P params) {
|
||||
ValidationService.ValidationResult passwordValidation = validationService.validatePassword(
|
||||
params.getPassword(), params.getPlayer().getName());
|
||||
params.getPassword(), params.getPlayer().getName());
|
||||
if (passwordValidation.hasError()) {
|
||||
commonService.send(params.getPlayer(), passwordValidation.getMessageKey(), passwordValidation.getArgs());
|
||||
return false;
|
||||
@ -88,7 +88,7 @@ abstract class AbstractPasswordRegisterExecutor<P extends AbstractPasswordRegist
|
||||
public void executePostPersistAction(P params) {
|
||||
final Player player = params.getPlayer();
|
||||
if (performLoginAfterRegister(params)) {
|
||||
if (commonService.getProperty(PluginSettings.USE_ASYNC_TASKS)) {
|
||||
if (commonService.getProperty(CommonSettings.USE_ASYNC_TASKS)) {
|
||||
bukkitService.runTaskAsynchronously(() -> asynchronousLogin.forceLogin(player));
|
||||
} else {
|
||||
bukkitService.scheduleSyncDelayedTask(() -> asynchronousLogin.forceLogin(player), SYNC_LOGIN_DELAY);
|
||||
|
||||
@ -10,6 +10,7 @@ import com.warrenstrange.googleauth.IGoogleAuthenticator;
|
||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.initialization.HasCleanup;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.CommonSettings;
|
||||
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -68,7 +69,7 @@ public class TotpAuthenticator implements HasCleanup {
|
||||
public TotpGenerationResult generateTotpKey(Player player) {
|
||||
GoogleAuthenticatorKey credentials = authenticator.createCredentials();
|
||||
String qrCodeUrl = GoogleAuthenticatorQRGenerator.getOtpAuthURL(
|
||||
settings.getProperty(PluginSettings.SERVER_NAME), player.getName(), credentials);
|
||||
settings.getProperty(CommonSettings.SERVER_NAME), player.getName(), credentials);
|
||||
return new TotpGenerationResult(credentials.getKey(), qrCodeUrl);
|
||||
}
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@ import com.github.Anon8281.universalScheduler.scheduling.tasks.MyScheduledTask;
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.initialization.SettingsDependent;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||
import fr.xephi.authme.settings.properties.CommonSettings;
|
||||
import org.bukkit.BanEntry;
|
||||
import org.bukkit.BanList;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -35,11 +35,17 @@ import static fr.xephi.authme.AuthMe.getScheduler;
|
||||
*/
|
||||
public class BukkitService implements SettingsDependent {
|
||||
|
||||
/** Number of ticks per second in the Bukkit main thread. */
|
||||
/**
|
||||
* Number of ticks per second in the Bukkit main thread.
|
||||
*/
|
||||
public static final int TICKS_PER_SECOND = 20;
|
||||
/** Number of ticks per minute. */
|
||||
/**
|
||||
* Number of ticks per minute.
|
||||
*/
|
||||
public static final int TICKS_PER_MINUTE = 60 * TICKS_PER_SECOND;
|
||||
/** Whether the server is running Folia. */
|
||||
/**
|
||||
* Whether the server is running Folia.
|
||||
*/
|
||||
private static final boolean isFolia = UniversalScheduler.isFolia;
|
||||
private final AuthMe authMe;
|
||||
private boolean useAsyncTasks;
|
||||
@ -121,6 +127,7 @@ public class BukkitService implements SettingsDependent {
|
||||
|
||||
/**
|
||||
* Runs the task synchronously if we are running Folia, else do nothing but run it.
|
||||
*
|
||||
* @param task the task to be run
|
||||
*/
|
||||
public void runTaskIfFolia(Runnable task) {
|
||||
@ -133,6 +140,7 @@ public class BukkitService implements SettingsDependent {
|
||||
|
||||
/**
|
||||
* Runs the task synchronously if we are running Folia, else do nothing but run it.
|
||||
*
|
||||
* @param task the task to be run
|
||||
*/
|
||||
public void runTaskIfFolia(Entity entity, Runnable task) {
|
||||
@ -145,6 +153,7 @@ public class BukkitService implements SettingsDependent {
|
||||
|
||||
/**
|
||||
* Runs the task synchronously if we are running Folia, else do nothing but run it.
|
||||
*
|
||||
* @param task the task to be run
|
||||
*/
|
||||
public void runTaskIfFolia(Location location, Runnable task) {
|
||||
@ -212,13 +221,13 @@ public class BukkitService implements SettingsDependent {
|
||||
* Returns a task that will repeatedly run asynchronously until cancelled,
|
||||
* starting after the specified number of server ticks.
|
||||
*
|
||||
* @param task the task to be run
|
||||
* @param delay the ticks to wait before running the task for the first
|
||||
* time
|
||||
* @param task the task to be run
|
||||
* @param delay the ticks to wait before running the task for the first
|
||||
* time
|
||||
* @param period the ticks to wait between runs
|
||||
* @return a BukkitTask that contains the id number
|
||||
* @throws IllegalArgumentException if task is null
|
||||
* @throws IllegalStateException if this was already scheduled
|
||||
* @throws IllegalStateException if this was already scheduled
|
||||
*/
|
||||
public MyScheduledTask runTaskTimerAsynchronously(UniversalRunnable task, long delay, long period) {
|
||||
return task.runTaskTimerAsynchronously(authMe, delay, period);
|
||||
@ -309,7 +318,7 @@ public class BukkitService implements SettingsDependent {
|
||||
*
|
||||
* @param event Event details
|
||||
* @throws IllegalStateException Thrown when an asynchronous event is
|
||||
* fired from synchronous code.
|
||||
* fired from synchronous code.
|
||||
*/
|
||||
public void callEvent(Event event) {
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
@ -320,7 +329,7 @@ public class BukkitService implements SettingsDependent {
|
||||
*
|
||||
* @param eventSupplier the event supplier: function taking a boolean specifying whether AuthMe is configured
|
||||
* in async mode or not
|
||||
* @param <E> the event type
|
||||
* @param <E> the event type
|
||||
* @return the event that was created and emitted
|
||||
*/
|
||||
public <E extends Event> E createAndCallEvent(Function<Boolean, E> eventSupplier) {
|
||||
@ -352,7 +361,7 @@ public class BukkitService implements SettingsDependent {
|
||||
/**
|
||||
* Dispatches a command on this server, and executes it if found.
|
||||
*
|
||||
* @param sender the apparent sender of the command
|
||||
* @param sender the apparent sender of the command
|
||||
* @param commandLine the command + arguments. Example: <code>test abc 123</code>
|
||||
* @return returns false if no target is found
|
||||
*/
|
||||
@ -372,14 +381,14 @@ public class BukkitService implements SettingsDependent {
|
||||
|
||||
@Override
|
||||
public void reload(Settings settings) {
|
||||
useAsyncTasks = settings.getProperty(PluginSettings.USE_ASYNC_TASKS);
|
||||
useAsyncTasks = settings.getProperty(CommonSettings.USE_ASYNC_TASKS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the specified bytes to bungeecord using the specified player connection.
|
||||
*
|
||||
* @param player the player
|
||||
* @param bytes the message
|
||||
* @param bytes the message
|
||||
*/
|
||||
public void sendBungeeMessage(Player player, byte[] bytes) {
|
||||
player.sendPluginMessage(authMe, "BungeeCord", bytes);
|
||||
@ -389,7 +398,7 @@ public class BukkitService implements SettingsDependent {
|
||||
* Send the specified bytes to bungeecord using the specified player connection.
|
||||
*
|
||||
* @param player the player
|
||||
* @param bytes the message
|
||||
* @param bytes the message
|
||||
*/
|
||||
public void sendVelocityMessage(Player player, byte[] bytes) {
|
||||
if (player != null) {
|
||||
@ -404,13 +413,13 @@ public class BukkitService implements SettingsDependent {
|
||||
* Adds a ban to the list. If a previous ban exists, this will
|
||||
* update the previous entry.
|
||||
*
|
||||
* @param ip the ip of the ban
|
||||
* @param reason reason for the ban, null indicates implementation default
|
||||
* @param ip the ip of the ban
|
||||
* @param reason reason for the ban, null indicates implementation default
|
||||
* @param expires date for the ban's expiration (unban), or null to imply
|
||||
* forever
|
||||
* @param source source of the ban, null indicates implementation default
|
||||
* forever
|
||||
* @param source source of the ban, null indicates implementation default
|
||||
* @return the entry for the newly created ban, or the entry for the
|
||||
* (updated) previous ban
|
||||
* (updated) previous ban
|
||||
*/
|
||||
public BanEntry banIp(String ip, String reason, Date expires, String source) {
|
||||
return Bukkit.getServer().getBanList(BanList.Type.IP).addBan(ip, reason, expires, source);
|
||||
|
||||
@ -11,6 +11,7 @@ import fr.xephi.authme.initialization.DataFolder;
|
||||
import fr.xephi.authme.message.MessagePathHelper;
|
||||
import fr.xephi.authme.permission.DefaultPermission;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.CommonSettings;
|
||||
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||
import org.yaml.snakeyaml.DumperOptions;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
@ -49,7 +50,7 @@ public class HelpTranslationGenerator {
|
||||
* @throws IOException if the help file cannot be written to
|
||||
*/
|
||||
public File updateHelpFile() throws IOException {
|
||||
String languageCode = settings.getProperty(PluginSettings.MESSAGES_LANGUAGE);
|
||||
String languageCode = settings.getProperty(CommonSettings.MESSAGES_LANGUAGE);
|
||||
File helpFile = new File(dataFolder, MessagePathHelper.createHelpMessageFilePath(languageCode));
|
||||
Map<String, Object> helpEntries = generateHelpMessageEntries();
|
||||
|
||||
|
||||
@ -7,6 +7,7 @@ import fr.xephi.authme.events.RestoreSessionEvent;
|
||||
import fr.xephi.authme.initialization.Reloadable;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.logger.ConsoleLoggerFactory;
|
||||
import fr.xephi.authme.settings.properties.CommonSettings;
|
||||
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||
import fr.xephi.authme.util.PlayerUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -78,7 +79,7 @@ public class SessionService implements Reloadable {
|
||||
long timeSinceLastLogin = System.currentTimeMillis() - auth.getLastLogin();
|
||||
|
||||
if (timeSinceLastLogin > 0
|
||||
&& timeSinceLastLogin < service.getProperty(PluginSettings.SESSIONS_TIMEOUT) * MILLIS_PER_MINUTE) {
|
||||
&& timeSinceLastLogin < service.getProperty(CommonSettings.SESSIONS_TIMEOUT) * MILLIS_PER_MINUTE) {
|
||||
if (PlayerUtils.getPlayerIp(player).equals(auth.getLastIp())) {
|
||||
return SessionState.VALID;
|
||||
} else {
|
||||
@ -100,6 +101,6 @@ public class SessionService implements Reloadable {
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
this.isEnabled = service.getProperty(PluginSettings.SESSIONS_ENABLED);
|
||||
this.isEnabled = service.getProperty(CommonSettings.SESSIONS_ENABLED);
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,6 +13,7 @@ import fr.xephi.authme.logger.LogLevel;
|
||||
import fr.xephi.authme.process.register.RegisterSecondaryArgument;
|
||||
import fr.xephi.authme.process.register.RegistrationType;
|
||||
import fr.xephi.authme.security.HashAlgorithm;
|
||||
import fr.xephi.authme.settings.properties.CommonSettings;
|
||||
import fr.xephi.authme.settings.properties.DatabaseSettings;
|
||||
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||
@ -222,7 +223,7 @@ public class SettingsMigrationService extends PlainMigrationService {
|
||||
private static boolean changeBooleanSettingToLogLevelProperty(PropertyReader reader,
|
||||
ConfigurationData configData) {
|
||||
final String oldPath = "Security.console.noConsoleSpam";
|
||||
final Property<LogLevel> newProperty = PluginSettings.LOG_LEVEL;
|
||||
final Property<LogLevel> newProperty = CommonSettings.LOG_LEVEL;
|
||||
if (!newProperty.isValidInResource(reader) && reader.contains(oldPath)) {
|
||||
logger.info("Moving '" + oldPath + "' to '" + newProperty.getPath() + "'");
|
||||
boolean oldValue = Optional.ofNullable(reader.getBoolean(oldPath)).orElse(false);
|
||||
|
||||
@ -6,6 +6,7 @@ import fr.xephi.authme.logger.ConsoleLoggerFactory;
|
||||
import fr.xephi.authme.security.HashAlgorithm;
|
||||
import fr.xephi.authme.security.crypts.Argon2;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import fr.xephi.authme.settings.properties.CommonSettings;
|
||||
import fr.xephi.authme.settings.properties.EmailSettings;
|
||||
import fr.xephi.authme.settings.properties.HooksSettings;
|
||||
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||
@ -54,8 +55,8 @@ public class SettingsWarner {
|
||||
}
|
||||
|
||||
// Output hint if sessions are enabled that the timeout must be positive
|
||||
if (settings.getProperty(PluginSettings.SESSIONS_ENABLED)
|
||||
&& settings.getProperty(PluginSettings.SESSIONS_TIMEOUT) <= 0) {
|
||||
if (settings.getProperty(CommonSettings.SESSIONS_ENABLED)
|
||||
&& settings.getProperty(CommonSettings.SESSIONS_TIMEOUT) <= 0) {
|
||||
logger.warning("Warning: Session timeout needs to be positive in order to work!");
|
||||
}
|
||||
|
||||
|
||||
@ -20,9 +20,11 @@ public final class AuthMeSettingsRetriever {
|
||||
*/
|
||||
public static ConfigurationData buildConfigurationData() {
|
||||
return ConfigurationDataBuilder.createConfiguration(
|
||||
CommonSettings.class,
|
||||
DatabaseSettings.class, PluginSettings.class, RestrictionSettings.class,
|
||||
EmailSettings.class, HooksSettings.class, ProtectionSettings.class,
|
||||
PurgeSettings.class, SecuritySettings.class, RegistrationSettings.class,
|
||||
LimboSettings.class, BackupSettings.class, ConverterSettings.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -40,32 +40,6 @@ public final class PluginSettings implements SettingsHolder {
|
||||
newLowercaseStringSetProperty("3rdPartyFeature.features.i18nMessages.locale-code-redirect",
|
||||
"tt_ru:ru", "lzh:zhcn");
|
||||
|
||||
@Comment({
|
||||
"Do you want to enable the session feature?",
|
||||
"If enabled, when a player authenticates successfully,",
|
||||
"his IP and his nickname is saved.",
|
||||
"The next time the player joins the server, if his IP",
|
||||
"is the same as last time and the timeout hasn't",
|
||||
"expired, he will not need to authenticate."
|
||||
})
|
||||
public static final Property<Boolean> SESSIONS_ENABLED =
|
||||
newProperty("settings.sessions.enabled", true);
|
||||
|
||||
@Comment({
|
||||
"After how many minutes should a session expire?",
|
||||
"A player's session ends after the timeout or if his IP has changed"
|
||||
})
|
||||
public static final Property<Integer> SESSIONS_TIMEOUT =
|
||||
newProperty("settings.sessions.timeout", 43200);
|
||||
|
||||
@Comment({
|
||||
"Message language, available languages:",
|
||||
"https://github.com/AuthMe/AuthMeReloaded/blob/master/docs/translations.md",
|
||||
"Example: zhcn, en"
|
||||
})
|
||||
public static final Property<String> MESSAGES_LANGUAGE =
|
||||
newProperty("settings.messagesLanguage", "en");
|
||||
|
||||
@Comment({
|
||||
"Enables switching a player to defined permission groups before they log in.",
|
||||
"See below for a detailed explanation."
|
||||
@ -99,21 +73,6 @@ public final class PluginSettings implements SettingsHolder {
|
||||
public static final Property<Boolean> FORCE_VAULT_HOOK =
|
||||
newProperty("settings.forceVaultHook", false);
|
||||
|
||||
@Comment({
|
||||
"Log level: INFO, FINE, DEBUG. Use INFO for general messages,",
|
||||
"FINE for some additional detailed ones (like password failed),",
|
||||
"and DEBUG for debugging"
|
||||
})
|
||||
public static final Property<LogLevel> LOG_LEVEL =
|
||||
newProperty(LogLevel.class, "settings.logLevel", LogLevel.FINE);
|
||||
|
||||
@Comment({
|
||||
"By default we schedule async tasks when talking to the database. If you want",
|
||||
"typical communication with the database to happen synchronously, set this to false"
|
||||
})
|
||||
public static final Property<Boolean> USE_ASYNC_TASKS =
|
||||
newProperty("settings.useAsyncTasks", true);
|
||||
|
||||
@Comment("The name of the server, used in some placeholders.")
|
||||
public static final Property<String> SERVER_NAME = newProperty("settings.serverName", "Your Minecraft Server");
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package fr.xephi.authme.util.message;
|
||||
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.CommonSettings;
|
||||
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -97,6 +98,6 @@ public class I18NUtils {
|
||||
return locale;
|
||||
}
|
||||
|
||||
return settings.getProperty(PluginSettings.MESSAGES_LANGUAGE);
|
||||
return settings.getProperty(CommonSettings.MESSAGES_LANGUAGE);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,62 @@
|
||||
package fr.xephi.authme.settings.properties;
|
||||
|
||||
import ch.jalu.configme.Comment;
|
||||
import ch.jalu.configme.SettingsHolder;
|
||||
import ch.jalu.configme.properties.Property;
|
||||
import fr.xephi.authme.logger.LogLevel;
|
||||
|
||||
import static ch.jalu.configme.properties.PropertyInitializer.newProperty;
|
||||
|
||||
/**
|
||||
* CommonSettings
|
||||
*
|
||||
* @author TheFloodDragon
|
||||
* @since 2024/7/11 20:19
|
||||
*/
|
||||
public final class CommonSettings implements SettingsHolder {
|
||||
|
||||
@Comment({
|
||||
"Message language, available languages:",
|
||||
"https://github.com/AuthMe/AuthMeReloaded/blob/master/docs/translations.md",
|
||||
"Example: zhcn, en"
|
||||
})
|
||||
public static final Property<String> MESSAGES_LANGUAGE =
|
||||
newProperty("settings.messagesLanguage", "en");
|
||||
|
||||
@Comment({
|
||||
"(Disabled since 2024.7.11) Log level: INFO, FINE, DEBUG. Use INFO for general messages,",
|
||||
"FINE for some additional detailed ones (like password failed),",
|
||||
"and DEBUG for debugging"
|
||||
})
|
||||
public static final Property<LogLevel> LOG_LEVEL =
|
||||
newProperty(LogLevel.class, "settings.logLevel", LogLevel.FINE);
|
||||
|
||||
@Comment({
|
||||
"By default we schedule async tasks when talking to the database. If you want",
|
||||
"typical communication with the database to happen synchronously, set this to false"
|
||||
})
|
||||
public static final Property<Boolean> USE_ASYNC_TASKS =
|
||||
newProperty("settings.useAsyncTasks", true);
|
||||
|
||||
@Comment({
|
||||
"Do you want to enable the session feature?",
|
||||
"If enabled, when a player authenticates successfully,",
|
||||
"his IP and his nickname is saved.",
|
||||
"The next time the player joins the server, if his IP",
|
||||
"is the same as last time and the timeout hasn't",
|
||||
"expired, he will not need to authenticate."
|
||||
})
|
||||
public static final Property<Boolean> SESSIONS_ENABLED =
|
||||
newProperty("settings.sessions.enabled", true);
|
||||
|
||||
@Comment({
|
||||
"After how many minutes should a session expire?",
|
||||
"A player's session ends after the timeout or if his IP has changed"
|
||||
})
|
||||
public static final Property<Integer> SESSIONS_TIMEOUT =
|
||||
newProperty("settings.sessions.timeout", 43200);
|
||||
|
||||
@Comment("The name of the server, used in some placeholders.")
|
||||
public static final Property<String> SERVER_NAME = newProperty("settings.serverName", "Your Minecraft Server");
|
||||
|
||||
}
|
||||
@ -1,6 +1,7 @@
|
||||
dependencies {
|
||||
compileOnly(project(":project:module-logger"))
|
||||
compileOnly(project(":project:module-util"))
|
||||
compileOnly(project(":project:module-security"))
|
||||
compileOnly(libs.configme)
|
||||
compileOnly(libs.jalu.injector)
|
||||
// Java Email Library
|
||||
|
||||
@ -4,8 +4,8 @@ import fr.xephi.authme.initialization.DataFolder;
|
||||
import fr.xephi.authme.logger.ConsoleLogger;
|
||||
import fr.xephi.authme.logger.ConsoleLoggerFactory;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.CommonSettings;
|
||||
import fr.xephi.authme.settings.properties.EmailSettings;
|
||||
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||
import fr.xephi.authme.util.FileUtils;
|
||||
import org.apache.commons.mail.EmailException;
|
||||
@ -184,7 +184,7 @@ public class EmailService {
|
||||
private String replaceTagsForPasswordMail(String mailText, String name, String newPass, String ip, String time) {
|
||||
return mailText
|
||||
.replace("<playername />", name)
|
||||
.replace("<servername />", settings.getProperty(PluginSettings.SERVER_NAME))
|
||||
.replace("<servername />", settings.getProperty(CommonSettings.SERVER_NAME))
|
||||
.replace("<generatedpass />", newPass)
|
||||
.replace("<playerip />", ip)
|
||||
.replace("<time />", time);
|
||||
@ -193,7 +193,7 @@ public class EmailService {
|
||||
private String replaceTagsForPasswordMail(String mailText, String name, String newPass, String time) {
|
||||
return mailText
|
||||
.replace("<playername />", name)
|
||||
.replace("<servername />", settings.getProperty(PluginSettings.SERVER_NAME))
|
||||
.replace("<servername />", settings.getProperty(CommonSettings.SERVER_NAME))
|
||||
.replace("<generatedpass />", newPass)
|
||||
.replace("<time />", time);
|
||||
}
|
||||
@ -201,7 +201,7 @@ public class EmailService {
|
||||
private String replaceTagsForVerificationEmail(String mailText, String name, String code, int minutesValid, String time) {
|
||||
return mailText
|
||||
.replace("<playername />", name)
|
||||
.replace("<servername />", settings.getProperty(PluginSettings.SERVER_NAME))
|
||||
.replace("<servername />", settings.getProperty(CommonSettings.SERVER_NAME))
|
||||
.replace("<generatedcode />", code)
|
||||
.replace("<minutesvalid />", String.valueOf(minutesValid))
|
||||
.replace("<time />", time);
|
||||
@ -210,7 +210,7 @@ public class EmailService {
|
||||
private String replaceTagsForRecoveryCodeMail(String mailText, String name, String code, int hoursValid, String time) {
|
||||
return mailText
|
||||
.replace("<playername />", name)
|
||||
.replace("<servername />", settings.getProperty(PluginSettings.SERVER_NAME))
|
||||
.replace("<servername />", settings.getProperty(CommonSettings.SERVER_NAME))
|
||||
.replace("<recoverycode />", code)
|
||||
.replace("<hoursvalid />", String.valueOf(hoursValid))
|
||||
.replace("<time />", time);
|
||||
@ -218,7 +218,7 @@ public class EmailService {
|
||||
|
||||
private String replaceTagsForShutDownMail(String mailText, String time) {
|
||||
return mailText
|
||||
.replace("<servername />", settings.getProperty(PluginSettings.SERVER_NAME))
|
||||
.replace("<servername />", settings.getProperty(CommonSettings.SERVER_NAME))
|
||||
.replace("<time />", time);
|
||||
}
|
||||
|
||||
|
||||
@ -4,6 +4,7 @@ import fr.xephi.authme.logger.ConsoleLogger;
|
||||
import fr.xephi.authme.logger.ConsoleLoggerFactory;
|
||||
import fr.xephi.authme.logger.LogLevel;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.CommonSettings;
|
||||
import fr.xephi.authme.settings.properties.EmailSettings;
|
||||
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
@ -66,7 +67,7 @@ public class SendMailSsl {
|
||||
email.setFrom(senderMail, senderName);
|
||||
email.setSubject(settings.getProperty(EmailSettings.RECOVERY_MAIL_SUBJECT));
|
||||
email.setAuthentication(settings.getProperty(EmailSettings.MAIL_ACCOUNT), mailPassword);
|
||||
if (settings.getProperty(PluginSettings.LOG_LEVEL).includes(LogLevel.DEBUG)) {
|
||||
if (settings.getProperty(CommonSettings.LOG_LEVEL).includes(LogLevel.DEBUG)) {
|
||||
email.setDebug(true);
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
dependencies {
|
||||
compileOnly(project(":project:module-logger"))
|
||||
compileOnly(libs.guava)
|
||||
// String comparison library. Used for dynamic help system.
|
||||
implementation("net.ricecode:string-similarity:1.0.0")
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
package fr.xephi.authme.util;
|
||||
|
||||
import com.google.common.io.Files;
|
||||
import fr.xephi.authme.logger.ConsoleLogger;
|
||||
import fr.xephi.authme.logger.ConsoleLoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@ -10,8 +8,6 @@ import java.io.InputStream;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
import static java.lang.String.format;
|
||||
|
||||
/**
|
||||
* File utilities.
|
||||
*/
|
||||
@ -20,8 +16,6 @@ public final class FileUtils {
|
||||
private static final DateTimeFormatter CURRENT_DATE_STRING_FORMATTER =
|
||||
DateTimeFormatter.ofPattern("yyyyMMdd_HHmm");
|
||||
|
||||
private static ConsoleLogger logger = ConsoleLoggerFactory.get(FileUtils.class);
|
||||
|
||||
// Utility class
|
||||
private FileUtils() {
|
||||
}
|
||||
@ -37,21 +31,20 @@ public final class FileUtils {
|
||||
if (destinationFile.exists()) {
|
||||
return true;
|
||||
} else if (!createDirectory(destinationFile.getParentFile())) {
|
||||
logger.warning("Cannot create parent directories for '" + destinationFile + "'");
|
||||
System.out.println("[warning] Cannot create parent directories for '" + destinationFile + "'");
|
||||
return false;
|
||||
}
|
||||
|
||||
try (InputStream is = getResourceFromJar(resourcePath)) {
|
||||
if (is == null) {
|
||||
logger.warning(format("Cannot copy resource '%s' to file '%s': cannot load resource",
|
||||
resourcePath, destinationFile.getPath()));
|
||||
System.out.printf("[warning] Cannot copy resource '%s' to file '%s': cannot load resource%n", resourcePath, destinationFile.getPath());
|
||||
} else {
|
||||
java.nio.file.Files.copy(is, destinationFile.toPath());
|
||||
return true;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.logException(format("Cannot copy resource '%s' to file '%s':",
|
||||
resourcePath, destinationFile.getPath()), e);
|
||||
System.out.printf("[warning] Cannot copy resource '%s' to file '%s':%n", resourcePath, destinationFile.getPath());
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -64,7 +57,7 @@ public final class FileUtils {
|
||||
*/
|
||||
public static boolean createDirectory(File dir) {
|
||||
if (!dir.exists() && !dir.mkdirs()) {
|
||||
logger.warning("Could not create directory '" + dir + "'");
|
||||
System.out.println("[warning] Could not create directory '" + dir + "'");
|
||||
return false;
|
||||
}
|
||||
return dir.isDirectory();
|
||||
@ -121,7 +114,7 @@ public final class FileUtils {
|
||||
if (file != null) {
|
||||
boolean result = file.delete();
|
||||
if (!result) {
|
||||
logger.warning("Could not delete file '" + file + "'");
|
||||
System.out.println("[warning] Could not delete file '" + file + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user