Skip to content

Commit

Permalink
Move some configuations from PluginSettings to CommonSettings (new cr…
Browse files Browse the repository at this point in the history
…eated)
  • Loading branch information
TheFloodDragon committed Jul 11, 2024
1 parent d22ec8c commit ea98f7b
Show file tree
Hide file tree
Showing 20 changed files with 134 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
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;
Expand Down Expand Up @@ -56,7 +57,7 @@ public static void sendMetrics(AuthMe plugin, Settings settings) {
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()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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;
Expand Down Expand Up @@ -45,15 +46,15 @@ protected AbstractMessageFileHandler() {
@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);
i18nConfiguration = null;
}

protected String getLanguage() {
return settings.getProperty(PluginSettings.MESSAGES_LANGUAGE);
return settings.getProperty(CommonSettings.MESSAGES_LANGUAGE);
}

protected File getUserLanguageFile() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
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;
Expand Down Expand Up @@ -193,7 +194,7 @@ private PlayerAuth getPlayerAuth(Player player, boolean quiet) {
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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
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;
Expand Down Expand Up @@ -97,7 +98,7 @@ public void processQuit(Player player) {
//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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
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;

Expand All @@ -21,7 +21,7 @@
* @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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -88,7 +88,7 @@ protected boolean performLoginAfterRegister(P params) {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
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;

Expand Down Expand Up @@ -68,7 +69,7 @@ public boolean checkCode(String playerName, String totpKey, String inputCode) {
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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
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;
Expand Down Expand Up @@ -35,11 +35,17 @@
*/
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;
Expand Down Expand Up @@ -121,6 +127,7 @@ public void runTask(Location location, Runnable task) {

/**
* 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) {
Expand All @@ -133,6 +140,7 @@ public void runTaskIfFolia(Runnable task) {

/**
* 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) {
Expand All @@ -145,6 +153,7 @@ public void runTaskIfFolia(Entity entity, Runnable task) {

/**
* 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) {
Expand Down Expand Up @@ -212,13 +221,13 @@ public void runTaskAsynchronously(Runnable task) {
* 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);
Expand Down Expand Up @@ -309,7 +318,7 @@ public Collection<Player> getOnlinePlayers() {
*
* @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);
Expand All @@ -320,7 +329,7 @@ public void callEvent(Event event) {
*
* @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) {
Expand Down Expand Up @@ -352,7 +361,7 @@ public World getWorld(String name) {
/**
* 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
*/
Expand All @@ -372,14 +381,14 @@ public boolean dispatchConsoleCommand(String commandLine) {

@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);
Expand All @@ -389,7 +398,7 @@ public void sendBungeeMessage(Player player, byte[] bytes) {
* 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) {
Expand All @@ -404,13 +413,13 @@ public void sendVelocityMessage(Player player, byte[] bytes) {
* 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
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;
Expand Down Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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;
Expand Down Expand Up @@ -78,7 +79,7 @@ private SessionState fetchSessionStatus(PlayerAuth auth, Player player) {
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 {
Expand All @@ -100,6 +101,6 @@ public void revokeSession(String name) {

@Override
public void reload() {
this.isEnabled = service.getProperty(PluginSettings.SESSIONS_ENABLED);
this.isEnabled = service.getProperty(CommonSettings.SESSIONS_ENABLED);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
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;
Expand Down Expand Up @@ -222,7 +223,7 @@ private static boolean migratePoolSizeSetting(PropertyReader reader, Configurati
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
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;
Expand Down Expand Up @@ -54,8 +55,8 @@ public void logWarningsForMisconfigurations() {
}

// 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!");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ private 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);
}

}
Loading

0 comments on commit ea98f7b

Please sign in to comment.