mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2025-02-17 04:11:33 +01:00
parent
2974e4f5cb
commit
591d6f1d4c
@ -140,7 +140,6 @@ public class AuthMe extends JavaPlugin {
|
||||
initialize();
|
||||
} catch (Throwable th) {
|
||||
ConsoleLogger.logException("Aborting initialization of AuthMe:", th);
|
||||
OnStartupTasks.displayLegacyJarHint(th);
|
||||
stopOrUnload();
|
||||
return;
|
||||
}
|
||||
@ -206,6 +205,7 @@ public class AuthMe extends JavaPlugin {
|
||||
if(!SystemUtils.isJavaVersionAtLeast(1.8f)) {
|
||||
throw new IllegalStateException("You need Java 1.8 or above to run this plugin!");
|
||||
}
|
||||
OnStartupTasks.verifyIfLegacyJarIsNeeded();
|
||||
|
||||
// Create plugin folder
|
||||
getDataFolder().mkdir();
|
||||
|
@ -1,6 +1,5 @@
|
||||
package fr.xephi.authme.initialization;
|
||||
|
||||
import ch.jalu.injector.exceptions.InjectorReflectionException;
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
@ -23,7 +22,6 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.Optional;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static fr.xephi.authme.service.BukkitService.TICKS_PER_MINUTE;
|
||||
@ -120,20 +118,19 @@ public class OnStartupTasks {
|
||||
|
||||
/**
|
||||
* Displays a hint to use the legacy AuthMe JAR if AuthMe could not be started
|
||||
* because Gson was not found.
|
||||
*
|
||||
* @param th the Throwable to process
|
||||
* because Gson or newer Guava classes were not found.
|
||||
*/
|
||||
public static void displayLegacyJarHint(Throwable th) {
|
||||
if (th instanceof InjectorReflectionException) {
|
||||
Throwable causeOfCause = Optional.of(th)
|
||||
.map(Throwable::getCause)
|
||||
.map(Throwable::getCause).orElse(null);
|
||||
if (causeOfCause instanceof NoClassDefFoundError
|
||||
&& "Lcom/google/gson/Gson;".equals(causeOfCause.getMessage())) {
|
||||
ConsoleLogger.warning("YOU MUST DOWNLOAD THE LEGACY JAR TO USE AUTHME ON YOUR SERVER");
|
||||
ConsoleLogger.warning("Get authme-legacy.jar from http://ci.xephi.fr/job/AuthMeReloaded/");
|
||||
}
|
||||
public static void verifyIfLegacyJarIsNeeded() {
|
||||
try {
|
||||
Class<?>[] classes = {
|
||||
com.google.common.base.MoreObjects.class, // < 1.12 Minecraft
|
||||
com.google.gson.Gson.class // < 1.7 Minecraft
|
||||
};
|
||||
} catch (NoClassDefFoundError e) {
|
||||
ConsoleLogger.warning("YOU MUST DOWNLOAD THE LEGACY JAR TO USE AUTHME ON YOUR SERVER");
|
||||
ConsoleLogger.warning("Get authme-legacy.jar from http://ci.xephi.fr/job/AuthMeReloaded/");
|
||||
ConsoleLogger.warning("Reason: could not load class '" + e.getMessage() + "'");
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
package fr.xephi.authme.initialization;
|
||||
|
||||
import ch.jalu.injector.exceptions.InjectorReflectionException;
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import fr.xephi.authme.security.HashAlgorithm;
|
||||
import org.junit.Test;
|
||||
@ -9,7 +8,6 @@ import java.util.logging.Logger;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
|
||||
/**
|
||||
@ -17,44 +15,13 @@ import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
*/
|
||||
public class OnStartupTasksTest {
|
||||
|
||||
@Test
|
||||
public void shouldDisplayLegacyJarHint() {
|
||||
// given
|
||||
Logger logger = TestHelper.setupLogger();
|
||||
NoClassDefFoundError noClassDefError = new NoClassDefFoundError("Lcom/google/gson/Gson;");
|
||||
ReflectiveOperationException ex2 = new ReflectiveOperationException("", noClassDefError);
|
||||
InjectorReflectionException ex = new InjectorReflectionException("", ex2);
|
||||
|
||||
// when
|
||||
OnStartupTasks.displayLegacyJarHint(ex);
|
||||
|
||||
// then
|
||||
verify(logger).warning("YOU MUST DOWNLOAD THE LEGACY JAR TO USE AUTHME ON YOUR SERVER");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotDisplayLegacyHintForDifferentException() {
|
||||
// given
|
||||
Logger logger = TestHelper.setupLogger();
|
||||
NullPointerException npe = new NullPointerException();
|
||||
|
||||
// when
|
||||
OnStartupTasks.displayLegacyJarHint(npe);
|
||||
|
||||
// then
|
||||
verifyZeroInteractions(logger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotDisplayLegacyHintForWrongCause() {
|
||||
// given
|
||||
Logger logger = TestHelper.setupLogger();
|
||||
IllegalAccessException illegalAccessException = new IllegalAccessException("Lcom/google/gson/Gson;");
|
||||
ReflectiveOperationException ex2 = new ReflectiveOperationException("", illegalAccessException);
|
||||
InjectorReflectionException ex = new InjectorReflectionException("", ex2);
|
||||
|
||||
// when
|
||||
OnStartupTasks.displayLegacyJarHint(ex);
|
||||
OnStartupTasks.verifyIfLegacyJarIsNeeded();
|
||||
|
||||
// then
|
||||
verifyZeroInteractions(logger);
|
||||
|
Loading…
Reference in New Issue
Block a user