From f88713c9b0229c2d0efedc16499fdd4a3a7913b0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?MC=7E=E8=9B=9F=E9=BE=99?= <1610105206@qq.com>
Date: Thu, 11 Jul 2024 19:02:06 +0800
Subject: [PATCH] Move mail [skip]
---
gradle/libs.versions.toml | 8 +-
plugin/build.gradle.kts | 14 +--
plugin/platform-bukkit/build.gradle.kts | 24 ++---
.../java/fr/xephi/authme/ConsoleLogger.java | 21 ++--
.../fr/xephi/authme/mail/ImageGenerator.java | 40 --------
.../fr/xephi/authme/mail/OAuth2Provider.java | 28 ------
.../xephi/authme/mail/OAuth2SaslClient.java | 98 -------------------
.../authme/mail/OAuth2SaslClientFactory.java | 57 -----------
.../settings/properties/BackupSettings.java | 8 +-
project/module-common/build.gradle.kts | 7 +-
project/module-configuration/build.gradle.kts | 12 +--
project/module-logger/build.gradle.kts | 1 +
.../xephi/authme/output/LogFilterHelper.java | 7 +-
.../fr/xephi/authme/mail/EmailService.java | 70 ++++++-------
.../fr/xephi/authme/mail/SendMailSsl.java | 4 +-
project/module-message/build.gradle.kts | 8 +-
project/module-util/build.gradle.kts | 7 +-
.../java/fr/xephi/authme/util/FileUtils.java | 26 +++--
18 files changed, 119 insertions(+), 321 deletions(-)
delete mode 100644 plugin/platform-bukkit/src/main/java/fr/xephi/authme/mail/ImageGenerator.java
delete mode 100644 plugin/platform-bukkit/src/main/java/fr/xephi/authme/mail/OAuth2Provider.java
delete mode 100644 plugin/platform-bukkit/src/main/java/fr/xephi/authme/mail/OAuth2SaslClient.java
delete mode 100644 plugin/platform-bukkit/src/main/java/fr/xephi/authme/mail/OAuth2SaslClientFactory.java
rename {plugin/platform-bukkit => project/module-mail}/src/main/java/fr/xephi/authme/mail/EmailService.java (76%)
rename {plugin/platform-bukkit => project/module-mail}/src/main/java/fr/xephi/authme/mail/SendMailSsl.java (97%)
rename {plugin/platform-bukkit => project/module-util}/src/main/java/fr/xephi/authme/util/FileUtils.java (88%)
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml
index 7b4ae447..5dbf935d 100644
--- a/gradle/libs.versions.toml
+++ b/gradle/libs.versions.toml
@@ -1,10 +1,12 @@
[versions]
guava = "33.2.1-jre"
-adventure = "4.17.0"
+configme = "1.3.1"
+adventure-api = "4.17.0"
adventure-platform = "4.3.2"
[libraries]
guava = { module = "com.google.guava:guava", version.ref = "guava" }
-adventure-text-minimessage = { module = "net.kyori:adventure-text-minimessage", version.ref = "adventure" }
-adventure-text-serializer-gson = { module = "net.kyori:adventure-text-serializer-gson", version.ref = "adventure" }
+configme = { module = "ch.jalu:configme", version.ref = "configme" }
+adventure-text-minimessage = { module = "net.kyori:adventure-text-minimessage", version.ref = "adventure-api" }
+adventure-text-serializer-gson = { module = "net.kyori:adventure-text-serializer-gson", version.ref = "adventure-api" }
adventure-platform-bukkit = { module = "net.kyori:adventure-platform-bukkit", version.ref = "adventure-platform" }
\ No newline at end of file
diff --git a/plugin/build.gradle.kts b/plugin/build.gradle.kts
index af917080..6959dc4e 100644
--- a/plugin/build.gradle.kts
+++ b/plugin/build.gradle.kts
@@ -21,14 +21,16 @@ subprojects {
dependencies {
// Modules
- implementation(project(":project:module-common", "shadow"))
- implementation(project(":project:module-util", "shadow"))
- implementation(project(":project:module-logger", "shadow"))
implementation(project(":project:module-configuration", "shadow"))
+ implementation(project(":project:module-logger", "shadow"))
+ implementation(project(":project:module-util", "shadow"))
+ implementation(project(":project:module-common", "shadow"))
implementation(project(":project:module-message", "shadow"))
+ implementation(project(":project:module-database", "shadow"))
+ implementation(project(":project:module-mail", "shadow"))
// Adventure API
- implementation("net.kyori:adventure-text-minimessage:4.17.0")
- implementation("net.kyori:adventure-text-serializer-gson:4.17.0")
+ implementation(rootProject.libs.adventure.text.minimessage)
+ implementation(rootProject.libs.adventure.text.serializer.gson)
// Spigot API, https://www.spigotmc.org/
compileOnly("org.spigotmc:spigot-api:1.20.6-R0.1-SNAPSHOT")
// Java Libraries
@@ -42,8 +44,6 @@ subprojects {
}
// Library for tar archives
implementation("javatar:javatar:2.5")
- // Java Email Library
- implementation("org.apache.commons:commons-email:1.6-SNAPSHOT")
// Log4J Logger (required by the console filter) TODO Remove
compileOnly("org.apache.logging.log4j:log4j-core:2.20.0") // Log4J version bundled in 1.12.2
// Libby
diff --git a/plugin/platform-bukkit/build.gradle.kts b/plugin/platform-bukkit/build.gradle.kts
index 744da80a..5fd80077 100644
--- a/plugin/platform-bukkit/build.gradle.kts
+++ b/plugin/platform-bukkit/build.gradle.kts
@@ -2,19 +2,19 @@ description = "Fork of the first authentication plugin for the Bukkit API!"
dependencies {
- // Adventure Bukkit
- implementation("net.kyori:adventure-platform-bukkit:4.3.2")
+ // Adventure Bukkit
+ implementation(libs.adventure.platform.bukkit)
- // Hooks - Start
- // bStats metrics
- implementation("org.bstats:bstats-bukkit:3.0.2")
- // ProtocolLib
- compileOnly("com.comphenix.protocol:ProtocolLib:5.1.0")
- // LuckPerms plugin
- compileOnly("net.luckperms:api:5.4")
- // PermissionsEx plugin
- compileOnly("ru.tehkode:PermissionsEx:1.23.5-SNAPSHOT")
- // Hooks - End
+ // Hooks - Start
+ // bStats metrics
+ implementation("org.bstats:bstats-bukkit:3.0.2")
+ // ProtocolLib
+ compileOnly("com.comphenix.protocol:ProtocolLib:5.1.0")
+ // LuckPerms plugin
+ compileOnly("net.luckperms:api:5.4")
+ // PermissionsEx plugin
+ compileOnly("ru.tehkode:PermissionsEx:1.23.5-SNAPSHOT")
+ // Hooks - End
}
diff --git a/plugin/platform-bukkit/src/main/java/fr/xephi/authme/ConsoleLogger.java b/plugin/platform-bukkit/src/main/java/fr/xephi/authme/ConsoleLogger.java
index 125bf477..9ab9974e 100644
--- a/plugin/platform-bukkit/src/main/java/fr/xephi/authme/ConsoleLogger.java
+++ b/plugin/platform-bukkit/src/main/java/fr/xephi/authme/ConsoleLogger.java
@@ -27,12 +27,15 @@ import java.util.logging.Logger;
public final class ConsoleLogger {
private static final String NEW_LINE = System.lineSeparator();
- /** Formatter which formats dates to something like "[08-16 21:18:46]" for any given LocalDateTime. */
+
+ /**
+ * Formatter which formats dates to something like "[08-16 21:18:46]" for any given LocalDateTime.
+ */
private static final DateTimeFormatter DATE_FORMAT = new DateTimeFormatterBuilder()
- .appendLiteral('[')
- .appendPattern("MM-dd HH:mm:ss")
- .appendLiteral(']')
- .toFormatter();
+ .appendLiteral('[')
+ .appendPattern("MM-dd HH:mm:ss")
+ .appendLiteral(']')
+ .toFormatter();
// Outside references
private static File logFile;
@@ -168,7 +171,7 @@ public final class ConsoleLogger {
* Log the DEBUG message.
*
* @param message the message
- * @param param1 parameter to replace in the message
+ * @param param1 parameter to replace in the message
*/
// Avoids array creation if DEBUG level is disabled
public void debug(String message, Object param1) {
@@ -181,8 +184,8 @@ public final class ConsoleLogger {
* Log the DEBUG message.
*
* @param message the message
- * @param param1 first param to replace in message
- * @param param2 second param to replace in message
+ * @param param1 first param to replace in message
+ * @param param2 second param to replace in message
*/
// Avoids array creation if DEBUG level is disabled
public void debug(String message, Object param1, Object param2) {
@@ -195,7 +198,7 @@ public final class ConsoleLogger {
* Log the DEBUG message.
*
* @param message the message
- * @param params the params to replace in the message
+ * @param params the params to replace in the message
*/
public void debug(String message, Object... params) {
if (logLevel.includes(LogLevel.DEBUG)) {
diff --git a/plugin/platform-bukkit/src/main/java/fr/xephi/authme/mail/ImageGenerator.java b/plugin/platform-bukkit/src/main/java/fr/xephi/authme/mail/ImageGenerator.java
deleted file mode 100644
index 24689dc3..00000000
--- a/plugin/platform-bukkit/src/main/java/fr/xephi/authme/mail/ImageGenerator.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package fr.xephi.authme.mail;
-
-import java.awt.*;
-import java.awt.image.BufferedImage;
-
-/**
- */
-public class ImageGenerator {
-
- private final String pass;
-
- /**
- * Constructor for ImageGenerator.
- *
- * @param pass String
- */
- public ImageGenerator(String pass) {
- this.pass = pass;
- }
-
- /**
- * Method generateImage.
- *
- * @return BufferedImage
- */
- public BufferedImage generateImage() {
- BufferedImage image = new BufferedImage(200, 60, BufferedImage.TYPE_BYTE_INDEXED);
- Graphics2D graphics = image.createGraphics();
- graphics.setColor(Color.BLACK);
- graphics.fillRect(0, 0, 200, 40);
- GradientPaint gradientPaint = new GradientPaint(10, 5, Color.WHITE, 20, 10, Color.WHITE, true);
- graphics.setPaint(gradientPaint);
- Font font = new Font("Comic Sans MS", Font.BOLD, 30);
- graphics.setFont(font);
- graphics.drawString(pass, 5, 30);
- graphics.dispose();
- image.flush();
- return image;
- }
-}
diff --git a/plugin/platform-bukkit/src/main/java/fr/xephi/authme/mail/OAuth2Provider.java b/plugin/platform-bukkit/src/main/java/fr/xephi/authme/mail/OAuth2Provider.java
deleted file mode 100644
index ee5c3cd0..00000000
--- a/plugin/platform-bukkit/src/main/java/fr/xephi/authme/mail/OAuth2Provider.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package fr.xephi.authme.mail;
-
-import java.security.Provider;
-
-/* Copyright 2012 Google Inc.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-public class OAuth2Provider extends Provider {
- private static final long serialVersionUID = 1L;
-
- public OAuth2Provider() {
- super("Google OAuth2 Provider", 1.0,
- "Provides the XOAUTH2 SASL Mechanism");
- put("SaslClientFactory.XOAUTH2",
- "fr.xephi.authme.mail.OAuth2SaslClientFactory");
- }
-}
\ No newline at end of file
diff --git a/plugin/platform-bukkit/src/main/java/fr/xephi/authme/mail/OAuth2SaslClient.java b/plugin/platform-bukkit/src/main/java/fr/xephi/authme/mail/OAuth2SaslClient.java
deleted file mode 100644
index 1f9b8c50..00000000
--- a/plugin/platform-bukkit/src/main/java/fr/xephi/authme/mail/OAuth2SaslClient.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/* Copyright 2012 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package fr.xephi.authme.mail;
-
-import javax.security.auth.callback.Callback;
-import javax.security.auth.callback.CallbackHandler;
-import javax.security.auth.callback.NameCallback;
-import javax.security.auth.callback.UnsupportedCallbackException;
-import javax.security.sasl.SaslClient;
-import javax.security.sasl.SaslException;
-import java.io.IOException;
-
-/**
- * An OAuth2 implementation of SaslClient.
- */
-class OAuth2SaslClient implements SaslClient {
- private final String oauthToken;
- private final CallbackHandler callbackHandler;
-
- private boolean isComplete = false;
-
- /**
- * Creates a new instance of the OAuth2SaslClient. This will ordinarily only
- * be called from OAuth2SaslClientFactory.
- */
- public OAuth2SaslClient(String oauthToken,
- CallbackHandler callbackHandler) {
- this.oauthToken = oauthToken;
- this.callbackHandler = callbackHandler;
- }
-
- public String getMechanismName() {
- return "XOAUTH2";
- }
-
- public boolean hasInitialResponse() {
- return true;
- }
-
- public byte[] evaluateChallenge(byte[] challenge) throws SaslException {
- if (isComplete) {
- // Empty final response from server, just ignore it.
- return new byte[] { };
- }
-
- NameCallback nameCallback = new NameCallback("Enter name");
- Callback[] callbacks = new Callback[] { nameCallback };
- try {
- callbackHandler.handle(callbacks);
- } catch (UnsupportedCallbackException e) {
- throw new SaslException("Unsupported callback: " + e);
- } catch (IOException e) {
- throw new SaslException("Failed to execute callback: " + e);
- }
- String email = nameCallback.getName();
-
- byte[] response = String.format("user=%s\1auth=Bearer %s\1\1", email,
- oauthToken).getBytes();
- isComplete = true;
- return response;
- }
-
- public boolean isComplete() {
- return isComplete;
- }
-
- public byte[] unwrap(byte[] incoming, int offset, int len)
- throws SaslException {
- throw new IllegalStateException();
- }
-
- public byte[] wrap(byte[] outgoing, int offset, int len)
- throws SaslException {
- throw new IllegalStateException();
- }
-
- public Object getNegotiatedProperty(String propName) {
- if (!isComplete()) {
- throw new IllegalStateException();
- }
- return null;
- }
-
- public void dispose() throws SaslException {
- }
-}
diff --git a/plugin/platform-bukkit/src/main/java/fr/xephi/authme/mail/OAuth2SaslClientFactory.java b/plugin/platform-bukkit/src/main/java/fr/xephi/authme/mail/OAuth2SaslClientFactory.java
deleted file mode 100644
index a3ec879e..00000000
--- a/plugin/platform-bukkit/src/main/java/fr/xephi/authme/mail/OAuth2SaslClientFactory.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright 2012 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package fr.xephi.authme.mail;
-
-import javax.security.auth.callback.CallbackHandler;
-import javax.security.sasl.SaslClient;
-import javax.security.sasl.SaslClientFactory;
-import java.util.Map;
-import java.util.logging.Logger;
-
-/**
- * A SaslClientFactory that returns instances of OAuth2SaslClient.
- *
- *
- * Only the "XOAUTH2" mechanism is supported. The {@code callbackHandler} is
- * passed to the OAuth2SaslClient. Other parameters are ignored.
- */
-public class OAuth2SaslClientFactory implements SaslClientFactory {
-
- private static final Logger logger = Logger.getLogger(OAuth2SaslClientFactory.class.getName());
-
- public static final String OAUTH_TOKEN_PROP = "mail.smpt.sasl.mechanisms.oauth2.oauthToken";
-
- public SaslClient createSaslClient(String[] mechanisms,
- String authorizationId, String protocol, String serverName,
- Map props, CallbackHandler callbackHandler) {
- boolean matchedMechanism = false;
- for (int i = 0; i < mechanisms.length; ++i) {
- if ("XOAUTH2".equalsIgnoreCase(mechanisms[i])) {
- matchedMechanism = true;
- break;
- }
- }
- if (!matchedMechanism) {
- logger.info("Failed to match any mechanisms");
- return null;
- }
- return new OAuth2SaslClient((String) props.get(OAUTH_TOKEN_PROP), callbackHandler);
- }
-
- public String[] getMechanismNames(Map props) {
- return new String[] { "XOAUTH2" };
- }
-}
diff --git a/plugin/platform-bukkit/src/main/java/fr/xephi/authme/settings/properties/BackupSettings.java b/plugin/platform-bukkit/src/main/java/fr/xephi/authme/settings/properties/BackupSettings.java
index 190c5b7d..7745d708 100644
--- a/plugin/platform-bukkit/src/main/java/fr/xephi/authme/settings/properties/BackupSettings.java
+++ b/plugin/platform-bukkit/src/main/java/fr/xephi/authme/settings/properties/BackupSettings.java
@@ -10,19 +10,19 @@ public final class BackupSettings implements SettingsHolder {
@Comment("General configuration for backups: if false, no backups are possible")
public static final Property ENABLED =
- newProperty("BackupSystem.ActivateBackup", false);
+ newProperty("BackupSystem.ActivateBackup", false);
@Comment("Create backup at every start of server")
public static final Property ON_SERVER_START =
- newProperty("BackupSystem.OnServerStart", false);
+ newProperty("BackupSystem.OnServerStart", false);
@Comment("Create backup at every stop of server")
public static final Property ON_SERVER_STOP =
- newProperty("BackupSystem.OnServerStop", true);
+ newProperty("BackupSystem.OnServerStop", true);
@Comment("Windows only: MySQL installation path")
public static final Property MYSQL_WINDOWS_PATH =
- newProperty("BackupSystem.MysqlWindowsPath", "C:\\Program Files\\MySQL\\MySQL Server 5.1\\");
+ newProperty("BackupSystem.MysqlWindowsPath", "C:\\Program Files\\MySQL\\MySQL Server 5.1\\");
private BackupSettings() {
}
diff --git a/project/module-common/build.gradle.kts b/project/module-common/build.gradle.kts
index 281f896d..dc8dec83 100644
--- a/project/module-common/build.gradle.kts
+++ b/project/module-common/build.gradle.kts
@@ -1 +1,6 @@
-dependencies {}
\ No newline at end of file
+dependencies {
+ compileOnly(project(":project:module-configuration"))
+ compileOnly(project(":project:module-logger"))
+ // ConfigMe
+ compileOnly(libs.configme)
+}
\ No newline at end of file
diff --git a/project/module-configuration/build.gradle.kts b/project/module-configuration/build.gradle.kts
index 368454ff..78cf2878 100644
--- a/project/module-configuration/build.gradle.kts
+++ b/project/module-configuration/build.gradle.kts
@@ -12,11 +12,9 @@ dependencies {
}
}
-tasks {
- shadowJar {
- // NightConfig
- relocate("com.electronwill.nightconfig", "com.electronwill.nightconfig_3_6_7")
- // Snakeyaml
- relocate("org.yaml.snakeyaml", "org.yaml.snakeyaml_2_2")
- }
+tasks.shadowJar {
+ // NightConfig
+ relocate("com.electronwill.nightconfig", "com.electronwill.nightconfig_3_6_7")
+ // Snakeyaml
+ relocate("org.yaml.snakeyaml", "org.yaml.snakeyaml_2_2")
}
\ No newline at end of file
diff --git a/project/module-logger/build.gradle.kts b/project/module-logger/build.gradle.kts
index fe9e26f7..0c2287dd 100644
--- a/project/module-logger/build.gradle.kts
+++ b/project/module-logger/build.gradle.kts
@@ -1,5 +1,6 @@
dependencies {
compileOnly(project(":project:module-util"))
+ compileOnly(project(":project:module-common"))
compileOnly(libs.guava)
// Log4J Logger (required by the console filter)
compileOnly("org.apache.logging.log4j:log4j-core:2.20.0") // Log4J version bundled in 1.12.2
diff --git a/project/module-logger/src/main/java/fr/xephi/authme/output/LogFilterHelper.java b/project/module-logger/src/main/java/fr/xephi/authme/output/LogFilterHelper.java
index 6058584a..2864fbab 100644
--- a/project/module-logger/src/main/java/fr/xephi/authme/output/LogFilterHelper.java
+++ b/project/module-logger/src/main/java/fr/xephi/authme/output/LogFilterHelper.java
@@ -15,9 +15,9 @@ final class LogFilterHelper {
@VisibleForTesting
static final List COMMANDS_TO_SKIP = withAndWithoutAuthMePrefix(
- "/login ", "/l ", "/log ", "/register ", "/reg ", "/unregister ", "/unreg ",
- "/changepassword ", "/cp ", "/changepass ", "/authme register ", "/authme reg ", "/authme r ",
- "/authme changepassword ", "/authme password ", "/authme changepass ", "/authme cp ", "/email setpassword ");
+ "/login ", "/l ", "/log ", "/register ", "/reg ", "/unregister ", "/unreg ",
+ "/changepassword ", "/cp ", "/changepass ", "/authme register ", "/authme reg ", "/authme r ",
+ "/authme changepassword ", "/authme password ", "/authme changepass ", "/authme cp ", "/email setpassword ");
private static final String ISSUED_COMMAND_TEXT = "issued server command:";
@@ -29,7 +29,6 @@ final class LogFilterHelper {
* Validate a message and return whether the message contains a sensitive AuthMe command.
*
* @param message The message to verify
- *
* @return True if it is a sensitive AuthMe command, false otherwise
*/
static boolean isSensitiveAuthMeCommand(String message) {
diff --git a/plugin/platform-bukkit/src/main/java/fr/xephi/authme/mail/EmailService.java b/project/module-mail/src/main/java/fr/xephi/authme/mail/EmailService.java
similarity index 76%
rename from plugin/platform-bukkit/src/main/java/fr/xephi/authme/mail/EmailService.java
rename to project/module-mail/src/main/java/fr/xephi/authme/mail/EmailService.java
index 76968fb9..c12c0bab 100644
--- a/plugin/platform-bukkit/src/main/java/fr/xephi/authme/mail/EmailService.java
+++ b/project/module-mail/src/main/java/fr/xephi/authme/mail/EmailService.java
@@ -40,7 +40,7 @@ public class EmailService {
return sendMailSsl.hasAllInformation();
}
- public boolean sendNewPasswordMail(String name, String mailAddress, String newPass,String ip,String time) {
+ public boolean sendNewPasswordMail(String name, String mailAddress, String newPass, String ip, String time) {
HtmlEmail email;
try {
email = sendMailSsl.initializeMail(mailAddress);
@@ -49,7 +49,7 @@ public class EmailService {
return false;
}
- String mailText = replaceTagsForPasswordMail(settings.getNewPasswordEmailMessage(), name, newPass,ip,time);
+ String mailText = replaceTagsForPasswordMail(settings.getNewPasswordEmailMessage(), name, newPass, ip, time);
File file = null;
if (settings.getProperty(EmailSettings.PASSWORD_AS_IMAGE)) {
try {
@@ -57,7 +57,7 @@ public class EmailService {
mailText = embedImageIntoEmailContent(file, email, mailText);
} catch (IOException | EmailException e) {
logger.logException(
- "Unable to send new password as image for email " + mailAddress + ":", e);
+ "Unable to send new password as image for email " + mailAddress + ":", e);
}
}
@@ -69,9 +69,9 @@ public class EmailService {
/**
* Sends an email to the user with his new password.
*
- * @param name the name of the player
+ * @param name the name of the player
* @param mailAddress the player's email
- * @param newPass the new password
+ * @param newPass the new password
* @return true if email could be sent, false otherwise
*/
public boolean sendPasswordMail(String name, String mailAddress, String newPass, String time) {
@@ -88,7 +88,7 @@ public class EmailService {
return false;
}
- String mailText = replaceTagsForPasswordMail(settings.getPasswordEmailMessage(), name, newPass,time);
+ String mailText = replaceTagsForPasswordMail(settings.getPasswordEmailMessage(), name, newPass, time);
// Generate an image?
File file = null;
if (settings.getProperty(EmailSettings.PASSWORD_AS_IMAGE)) {
@@ -97,7 +97,7 @@ public class EmailService {
mailText = embedImageIntoEmailContent(file, email, mailText);
} catch (IOException | EmailException e) {
logger.logException(
- "Unable to send new password as image for email " + mailAddress + ":", e);
+ "Unable to send new password as image for email " + mailAddress + ":", e);
}
}
@@ -105,6 +105,7 @@ public class EmailService {
FileUtils.delete(file);
return couldSendEmail;
}
+
/**
* Sends an email to the user with the temporary verification code.
*
@@ -127,16 +128,16 @@ public class EmailService {
}
String mailText = replaceTagsForVerificationEmail(settings.getVerificationEmailMessage(), name, code,
- settings.getProperty(SecuritySettings.VERIFICATION_CODE_EXPIRATION_MINUTES),time);
+ settings.getProperty(SecuritySettings.VERIFICATION_CODE_EXPIRATION_MINUTES), time);
sendMailSsl.sendEmail(mailText, email);
}
/**
* Sends an email to the user with a recovery code for the password recovery process.
*
- * @param name the name of the player
+ * @param name the name of the player
* @param email the player's email address
- * @param code the recovery code
+ * @param code the recovery code
* @return true if email could be sent, false otherwise
*/
public boolean sendRecoveryCode(String name, String email, String code, String time) {
@@ -149,7 +150,7 @@ public class EmailService {
}
String message = replaceTagsForRecoveryCodeMail(settings.getRecoveryCodeEmailMessage(),
- name, code, settings.getProperty(SecuritySettings.RECOVERY_CODE_HOURS_VALID),time);
+ name, code, settings.getProperty(SecuritySettings.RECOVERY_CODE_HOURS_VALID), time);
return sendMailSsl.sendEmail(message, htmlEmail);
}
@@ -174,50 +175,51 @@ public class EmailService {
}
private static String embedImageIntoEmailContent(File image, HtmlEmail email, String content)
- throws EmailException {
+ throws EmailException {
DataSource source = new FileDataSource(image);
String tag = email.embed(source, image.getName());
return content.replace("", "
");
}
- private String replaceTagsForPasswordMail(String mailText, String name, String newPass,String ip,String time) {
+ private String replaceTagsForPasswordMail(String mailText, String name, String newPass, String ip, String time) {
return mailText
- .replace("", name)
- .replace("", settings.getProperty(PluginSettings.SERVER_NAME))
- .replace("", newPass)
- .replace("", ip)
- .replace("", time);
+ .replace("", name)
+ .replace("", settings.getProperty(PluginSettings.SERVER_NAME))
+ .replace("", newPass)
+ .replace("", ip)
+ .replace("", time);
}
private String replaceTagsForPasswordMail(String mailText, String name, String newPass, String time) {
return mailText
- .replace("", name)
- .replace("", settings.getProperty(PluginSettings.SERVER_NAME))
- .replace("", newPass)
- .replace("", time);
+ .replace("", name)
+ .replace("", settings.getProperty(PluginSettings.SERVER_NAME))
+ .replace("", newPass)
+ .replace("", time);
}
private String replaceTagsForVerificationEmail(String mailText, String name, String code, int minutesValid, String time) {
return mailText
- .replace("", name)
- .replace("", settings.getProperty(PluginSettings.SERVER_NAME))
- .replace("", code)
- .replace("", String.valueOf(minutesValid))
- .replace("", time);
+ .replace("", name)
+ .replace("", settings.getProperty(PluginSettings.SERVER_NAME))
+ .replace("", code)
+ .replace("", String.valueOf(minutesValid))
+ .replace("", time);
}
private String replaceTagsForRecoveryCodeMail(String mailText, String name, String code, int hoursValid, String time) {
return mailText
- .replace("", name)
- .replace("", settings.getProperty(PluginSettings.SERVER_NAME))
- .replace("", code)
- .replace("", String.valueOf(hoursValid))
- .replace("", time);
+ .replace("", name)
+ .replace("", settings.getProperty(PluginSettings.SERVER_NAME))
+ .replace("", code)
+ .replace("", String.valueOf(hoursValid))
+ .replace("", time);
}
+
private String replaceTagsForShutDownMail(String mailText, String time) {
return mailText
- .replace("", settings.getProperty(PluginSettings.SERVER_NAME))
- .replace("", time);
+ .replace("", settings.getProperty(PluginSettings.SERVER_NAME))
+ .replace("", time);
}
}
diff --git a/plugin/platform-bukkit/src/main/java/fr/xephi/authme/mail/SendMailSsl.java b/project/module-mail/src/main/java/fr/xephi/authme/mail/SendMailSsl.java
similarity index 97%
rename from plugin/platform-bukkit/src/main/java/fr/xephi/authme/mail/SendMailSsl.java
rename to project/module-mail/src/main/java/fr/xephi/authme/mail/SendMailSsl.java
index b7e9fd41..bcc60f5a 100644
--- a/plugin/platform-bukkit/src/main/java/fr/xephi/authme/mail/SendMailSsl.java
+++ b/project/module-mail/src/main/java/fr/xephi/authme/mail/SendMailSsl.java
@@ -38,8 +38,8 @@ public class SendMailSsl {
* @return true if the necessary email settings are set, false otherwise
*/
public boolean hasAllInformation() {
- return !settings.getProperty(MAIL_ACCOUNT).isEmpty()
- && !settings.getProperty(MAIL_PASSWORD).isEmpty();
+ return !settings.getProperty(EmailSettings.MAIL_ACCOUNT).isEmpty()
+ && !settings.getProperty(EmailSettings.MAIL_PASSWORD).isEmpty();
}
/**
diff --git a/project/module-message/build.gradle.kts b/project/module-message/build.gradle.kts
index 281f896d..0a9a2c2d 100644
--- a/project/module-message/build.gradle.kts
+++ b/project/module-message/build.gradle.kts
@@ -1 +1,7 @@
-dependencies {}
\ No newline at end of file
+dependencies {
+ compileOnly(project(":project:module-common"))
+ compileOnly(project(":project:module-util"))
+ compileOnly(project(":project:module-logger"))
+ compileOnly(project(":project:module-configuration"))
+ compileOnly(project(":project:module-message"))
+}
\ No newline at end of file
diff --git a/project/module-util/build.gradle.kts b/project/module-util/build.gradle.kts
index ccd23619..bf78ed70 100644
--- a/project/module-util/build.gradle.kts
+++ b/project/module-util/build.gradle.kts
@@ -1,11 +1,10 @@
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")
}
-tasks {
- shadowJar {
- relocate("net.ricecode.similarity", "${project.group}.libs.net.ricecode.similarity")
- }
+tasks.shadowJar {
+ relocate("net.ricecode.similarity", "${project.group}.libs.net.ricecode.similarity")
}
\ No newline at end of file
diff --git a/plugin/platform-bukkit/src/main/java/fr/xephi/authme/util/FileUtils.java b/project/module-util/src/main/java/fr/xephi/authme/util/FileUtils.java
similarity index 88%
rename from plugin/platform-bukkit/src/main/java/fr/xephi/authme/util/FileUtils.java
rename to project/module-util/src/main/java/fr/xephi/authme/util/FileUtils.java
index 7f7ee4aa..86be894a 100644
--- a/plugin/platform-bukkit/src/main/java/fr/xephi/authme/util/FileUtils.java
+++ b/project/module-util/src/main/java/fr/xephi/authme/util/FileUtils.java
@@ -1,7 +1,6 @@
package fr.xephi.authme.util;
import com.google.common.io.Files;
-import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.output.ConsoleLoggerFactory;
@@ -19,7 +18,7 @@ import static java.lang.String.format;
public final class FileUtils {
private static final DateTimeFormatter CURRENT_DATE_STRING_FORMATTER =
- DateTimeFormatter.ofPattern("yyyyMMdd_HHmm");
+ DateTimeFormatter.ofPattern("yyyyMMdd_HHmm");
private static ConsoleLogger logger = ConsoleLoggerFactory.get(FileUtils.class);
@@ -32,7 +31,6 @@ public final class FileUtils {
*
* @param destinationFile The file to check and copy to (outside of JAR)
* @param resourcePath Local path to the resource file (path to file within JAR)
- *
* @return False if the file does not exist and could not be copied, true otherwise
*/
public static boolean copyFileFromResource(File destinationFile, String resourcePath) {
@@ -46,14 +44,14 @@ public final class FileUtils {
try (InputStream is = getResourceFromJar(resourcePath)) {
if (is == null) {
logger.warning(format("Cannot copy resource '%s' to file '%s': cannot load resource",
- resourcePath, destinationFile.getPath()));
+ 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);
+ resourcePath, destinationFile.getPath()), e);
}
return false;
}
@@ -78,10 +76,18 @@ public final class FileUtils {
* @param path the local path (starting from resources project, e.g. "config.yml" for 'resources/config.yml')
* @return the stream if the file exists, or false otherwise
*/
- public static InputStream getResourceFromJar(String path) {
+ public static InputStream getResourceFromJar(String path, ClassLoader classLoader) {
// ClassLoader#getResourceAsStream does not deal with the '\' path separator: replace to '/'
final String normalizedPath = path.replace("\\", "/");
- return AuthMe.class.getClassLoader().getResourceAsStream(normalizedPath);
+ return classLoader.getResourceAsStream(normalizedPath);
+ }
+
+ /**
+ * Returns a JAR file as stream. Returns null if it doesn't exist.
+ * And it will find resources in the classLoader of FileUtils
+ */
+ public static InputStream getResourceFromJar(String path) {
+ return getResourceFromJar(path, FileUtils.class.getClassLoader());
}
/**
@@ -140,7 +146,6 @@ public final class FileUtils {
* Construct a file path from the given elements, i.e. separate the given elements by the file separator.
*
* @param elements The elements to create a path with
- *
* @return The created path
*/
public static String makePath(String... elements) {
@@ -166,8 +171,9 @@ public final class FileUtils {
*/
public static String createBackupFilePath(File file) {
String filename = "backup_" + Files.getNameWithoutExtension(file.getName())
- + "_" + createCurrentTimeString()
- + "." + Files.getFileExtension(file.getName());
+ + "_" + createCurrentTimeString()
+ + "." + Files.getFileExtension(file.getName());
return makePath(file.getParent(), filename);
}
+
}